如何查询指定多个字段值的数据?

比如,有如下一张表:

Id = stretch(1..100,1000)
area = take(`A`B`C`D`E`F`G`H`I`J,1000)
qyt = rand(100.00,1000)
t  = table(Id,area,qyt)

我要查询以下条件的数据:

attachments-2022-12-QiDSImVb63aea260cf7fc.png采用如下查询语句,太麻烦了:

select * from t where (Id =1 and area = `A) or (Id = 1 and area = `F) or(Id = 1 and area = `G)

有没有简单点的写法?

请先 登录 后评论

1 个回答

wangsenxiao

可以先将参与筛选的多个字段拼接为一个新的字段,如下代码所示:

temp = select *,string(Id)+area as newCol from t

筛选条件涉及Id列和area列,将这两个字段拼接为一共新的字段newCol,然后再进行查询:

aim_row = `1A`1F`1G`2B`2C`2D`3B`3C`3G
result = select Id,area, qyt from temp where newCol in aim_row

查询结果如下:

attachments-2022-12-x0ktxs7463aea4b8dd711.png

请先 登录 后评论
  • 1 关注
  • 0 收藏,692 浏览
  • xuehaiwuya 提出于 2022-12-30 16:38

相似问题