我有两张桌子:
ad ( id(int) , userid(int) )
:用于存储具有用户列
的广告的表
adcat ( adid(int) , catid(int) )
:用于存储每个广告(adid)
现在我想要的是获取特定用户发布的特定类别的广告数量
示例:catid = 1且userid = 725
的所有广告谢谢
答案 0 :(得分:3)
SELECT * FROM ad
LEFT JOIN adcat
ON adcat.adid = ad.id
WHERE adcat.catid = 1 AND ad.userid = 725
答案 1 :(得分:2)
SELECT COUNT(*) ads_total
FROM ad a JOIN
adcat c ON a.id = c.adid
WHERE c.catid = 1 AND
a.userid = 725
<强> SQLFiddle 强>
答案 2 :(得分:1)
你需要加入表格:
SELECT * FROM ad INNER JOIN adcat ON adid=id WHERE catid=1 and userid=725;