我尝试计数行并同时获取数据

时间:2018-10-18 12:06:35

标签: mysql sql database

SELECT  * , 
       count(*) as num_row , 
       tbl_posts.id AS post_id, 
       tbl_posts.public_id AS post_public_id 
FROM  tbl_posts  
INNER JOIN tbl_users ON tbl_users.id = tbl_posts.user_id 
WHERE slug= "wrong slug" AND 
      tbl_posts.public_id = "wrong id" 
GROUP BY post_id

我尝试同时计算行数并获取数据,如果  条件正确但条件错误时COUNT函数不显示“ 0”,为什么以及如何解决?

0 个答案:

没有答案