gpt4 book ai didi

mysql - 将多个表的计数加入查询

转载 作者:行者123 更新时间:2023-11-30 23:26:14 25 4
gpt4 key购买 nike

我想从一个表中选择列并根据另外两个表的连接进行计数,我该怎么做?

这是我写的计数查询:

   SELECT COUNT(*) AS num_review FROM approved_reviews  m, reviews u where 
m.review_id_=u.id and u.item_id =? and m.approved=1

我想加入它

select item_id, item_name, item_price from items ?

我该怎么做?

最佳答案

select * 
from
(SELECT COUNT(*) AS num_review, u.item_id FROM approved_reviews m, reviews u where
m.review_id_=u.id and u.item_id =? and m.approved=1 group by u.item_id) count_sub,
(select item_id, item_name, item_price from items) item_sub
where item_sub.item_id = count_sub.item_id

关于mysql - 将多个表的计数加入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13208638/

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