gpt4 book ai didi

mysql - 统计mysql上的每一行

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

我有这个查询:

SELECT 
(SELECT COUNT(*) FROM tb_pinturas WHERE c.catId= 4) AS desejo,
(SELECT COUNT(*) FROM tb_pinturas WHERE c.catId= 2) AS europa,
(SELECT COUNT(*) FROM tb_pinturas WHERE c.catId= 6) AS futebol,
(SELECT COUNT(*) FROM tb_pinturas WHERE c.catId= 8) AS jazz,
(SELECT COUNT(*) FROM tb_pinturas WHERE c.catId= 3) AS praia,
(SELECT COUNT(*) FROM tb_pinturas WHERE c.catId= 1) AS sp,
(SELECT COUNT(*) FROM tb_pinturas WHERE c.catId= 7) AS tamta,
(SELECT COUNT(*) FROM tb_pinturas WHERE c.catId= 5) AS velocidade,
c.catNome AS nome,
c.catSlug AS slug,
c.catId AS id
FROM aux_categoria c
LEFT JOIN tb_pinturas p ON(c.catId = p.catId)
GROUP BY c.catid ORDER BY c.catNome;

我只想为每个计数制作一列。我该怎么办?

最佳答案

这样的东西应该适合你:

SELECT 
c.catNome AS nome,
c.catId AS id,
count(p.catId) as the_count
FROM aux_categoria c
LEFT JOIN tb_pinturas p ON(c.catId = p.catId)
GROUP BY c.catNome,c.catid
ORDER BY c.catNome

关于mysql - 统计mysql上的每一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20663067/

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