Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两张桌子:
ad ( id(int) , userid(int) ): 用于存储具有用户列的广告的 adcat ( adid(int) , catid(int) )表 : 用于存储每个广告 (adid) 的类别 ID (catid) 的表
ad ( id(int) , userid(int) )
adcat ( adid(int) , catid(int) )
现在我想要的只是获取特定用户发布的特定类别的广告数量
示例:所有 catid = 1 且 userid = 725 的广告
谢谢
SELECT * FROM ad LEFT JOIN adcat ON adcat.adid = ad.id WHERE adcat.catid = 1 AND ad.userid = 725
尝试使用JOIN和COUNT
JOIN
COUNT
SELECT COUNT(*) ads_total FROM ad a JOIN adcat c ON a.id = c.adid WHERE c.catid = 1 AND a.userid = 725
SQLFiddle
你需要加入表格:
SELECT * FROM ad INNER JOIN adcat ON adid=id WHERE catid=1 and userid=725;