繁体   English   中英

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

[英]Selecting two certain rows from a result table?

如果我的结果行如下:

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);

在这里演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM