gpt4 book ai didi

mysql - 在查询中生成 "Fake"记录

转载 作者:可可西里 更新时间:2023-11-01 07:01:19 25 4
gpt4 key购买 nike

我有一个非常基本的陈述,例如:

SELECT pet, animal_type, number_of_legs 
FROM table

但是,在当前 table 所在的位置,我想插入一些假数据,按照以下行:

rufus       cat     3
franklin turtle 1
norm dog 5

是否可以从查询中“生成”这些假记录,将每个值与相应的字段相关联,以便将它们作为查询结果返回?

最佳答案

SELECT pet, animal_type, number_of_legs FROM table
union select 'rufus', 'cat', 3
union select 'franklin', 'turtle', 1
union select 'norm', 'dog', 5

这给你 table 的内容加上你想要的 3 条记录,避免重复,如果可以重复,则将 union 替换为 union all

编辑:根据您的评论,对于 tsql,您可以:

select top 110 'franklin', 'turtle', 1
from sysobjects a, sysobjects b -- this cross join gives n^2 records

一定要选择n^2大于需要记录的表或者反复交叉连接

关于mysql - 在查询中生成 "Fake"记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29654265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com