any或者some,也就是任何值。
1.select clients with at least two invoices
步骤一:计算每个客户的发票数
select
client_id,count(*)
from invoices
group by client_id

步骤二:筛选大于2张发票的
select
client_id,count(*)
from invoices
group by client_id
having count(*)>=2

2,如果要得到,上述有两张以上发票的客户的具体信息
select *
from clients
where client_id in(
select
client_id
from invoices
group by client_id
having count(*)>=2)
注意:1,这里要用in,用=会显示Error Code: 1242. Subquery returns more than 1 row
如果要用=,那么要在等号之后加上any 。=any即in
select *
from clients
where client_id =any(
select
client_id
from invoices
group by client_id
having count(*)>=2)
2,select client_id,count(*),这个要去掉,不然 Error Code: 1241. Operand should contain 1 column(s)
本文介绍了如何使用SQL查询找出具有至少两张发票的客户,首先计算每个客户的发票数量,然后筛选出满足条件的客户ID,最后提供获取这些客户详细信息的方法。
1725

被折叠的 条评论
为什么被折叠?



