gpt4 book ai didi

mysql - 如何在mysql中使用count(*) WHERE IN

转载 作者:行者123 更新时间:2023-11-29 02:31:41 25 4
gpt4 key购买 nike

SELECT COUNT(*) FROM `product` where barcode in (681155,
681144,
681145,
681146,
681147,
681148,
688123,
688124,
688125,
688126) GROUP BY(barcode);

这个语句如何使用count(*)?我得到所有行的 1

最佳答案

尝试:

SELECT COUNT(*) FROM `product` 
where barcode in
(681155,
681144,
681145,
681146,
681147,
681148,
688123,
688124,
688125,
688126)

这将为您提供表格中的总数

当您使用 GROUP BY 时,它将对每个组进行计数。

SELECT barcode ,COUNT(*) FROM `product` 
    where barcode in (....)
Group by barcode

如果你对所有行都得到一个,那么你的表包含不同的条形码

关于mysql - 如何在mysql中使用count(*) WHERE IN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12315000/

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