gpt4 book ai didi

mysql - 从结果表中选择两个特定行?

转载 作者:行者123 更新时间:2023-11-29 07:37:14 26 4
gpt4 key购买 nike

如果我的结果行如下:

ID    Name     Rate_Type
1 xxxx 9
2 zzzz 22
3 cccc 12
4 eeee 17
5 uuuu 90

现在如何选择费率类型 = 9 的行和任何其他行。我希望我的查询能够告诉我是否存在 Rate_type 9 的行,并给出 ID 为 <> 9

的一行

我想要这个结果(只有两行结果):

ID    Name     Rate_Type
1 xxxx 9
! !!!! !--> This should be one additional row with Rate_Type <>9

最佳答案

您可以使用 union 来执行此操作两个查询。一个得到你的 rate_type = 9 ,以及获得您的 rate_type <> 9 的一个

(select * from t where rate_type = 9 order by rand() limit 1) 
union all
(select * from t where rate_type <> 9 order by rand() limit 1);

demo here

关于mysql - 从结果表中选择两个特定行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30341431/

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