gpt4 book ai didi

mysql - 带有子查询的两个表的总和

转载 作者:行者123 更新时间:2023-11-29 13:16:34 26 4
gpt4 key购买 nike

我有疑问

SELECT c.user_id, 
(SELECT COUNT(*) FROM jos_findme_bestof b WHERE b.user_id = c.user_id) as bCount,
(SELECT COUNT(*) FROM jos_findme_pair p WHERE p.user_id = c.user_id) as pCount,
(SELECT COUNT(*) FROM jos_findme_style s WHERE s.user_id = c.user_id) as sCount,

FROM jos_findme c

如何使用 bCount + pCount + sCount 创建列?

谢谢

最佳答案

如果您想在查询中添加该列:

   SELECT *,(bCount+pCount+sCount) as sumCount FROM(
SELECT c.user_id,
(SELECT COUNT(*) FROM jos_findme_bestof b WHERE b.user_id = c.user_id) as bCount,
(SELECT COUNT(*) FROM jos_findme_pair p WHERE p.user_id = c.user_id) as pCount,
(SELECT COUNT(*) FROM jos_findme_style s WHERE s.user_id = c.user_id) as sCount,

FROM jos_findme c)

关于mysql - 带有子查询的两个表的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21378383/

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