gpt4 book ai didi

mysql - 选择查询对项目进行分组但也进行限制

转载 作者:行者123 更新时间:2023-11-29 12:52:22 25 4
gpt4 key购买 nike

我正在运行这个sql查询:

SELECT * FROM customer_billing a WHERE 

(SELECT COUNT(*) FROM customer_billing b WHERE
a.producttype = 'VoIP Telephony' and
a.productname = 'VoIP Geographic Number (01/02)' and
a.customer_seq = b.customer_seq)
<= 1 order by customer_seq ASC

它应该只显示 producttype = 'VoIP Telephony' 的行,但它显示其他两个

其中producttype =“电话线路”等

最佳答案

我认为你正在尝试这样做:

SELECT *
FROM customer_billing cb
WHERE cb.producttype = 'VoIP Telephony' and
cb.productname = 'VoIP Geographic Number (01/02)' and
(SELECT COUNT(*)
FROM customer_billing cb2
WHERE cb2.producttype = cb.producttype and
cb2.productname = cb.productname and
cb2.customer_seq = cb.customer_seq
) <= 1
order by customer_seq ASC;

您的查询版本正在子查询内进行比较。因此它们仅适用于 count(*) 而不是整个查询的过滤。

关于mysql - 选择查询对项目进行分组但也进行限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24542101/

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