gpt4 book ai didi

php - Mysql distinct with count with 条件

转载 作者:行者123 更新时间:2023-11-29 05:21:04 25 4
gpt4 key购买 nike

this question记在心里

SELECT COUNT(DISTINCT productId) WHERE keyword='$keyword'

如何根据条件获取不同行的数量

SELECT COUNT(DISTINCT productId -- THIS IS WHERE I NEED TO PUT CONDITION --) WHERE keyword='$keyword'

如果该行没有 type <> 1,我需要继续不同的行

最佳答案

我不确定,但你在找这个吗:

SELECT COUNT(DISTINCT productId) from table_name WHERE keyword='$keyword' and type!=1

编辑:

SELECT COUNT(DISTINCT CASE WHEN type <> 1 
THEN productId
ELSE NULL
END
)
FROM table_name
WHERE keyword='$keyword'

关于php - Mysql distinct with count with 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25721796/

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