当 MySQL 返回的查询结果为空(即零行)的时候 结果表示0
当查询之后,查询结果为0,但是并没有表示出来。SELECTupdate_date,user_id,news_id,count(*)AScounterFROMt_comme...
当查询之后,查询结果为0,但是并没有表示出来。
SELECT update_date, user_id, news_id,
count(*) AS counter FROM t_comment
WHERE user_id = 2
AND news_id = 15
GROUP BY user_id, news_id
我想表示出来 MYSQL应该怎么写 谢谢
update_date user_id news_id counter
2008-03-08 2 15 0 (此处显示0) 展开
SELECT update_date, user_id, news_id,
count(*) AS counter FROM t_comment
WHERE user_id = 2
AND news_id = 15
GROUP BY user_id, news_id
我想表示出来 MYSQL应该怎么写 谢谢
update_date user_id news_id counter
2008-03-08 2 15 0 (此处显示0) 展开
展开全部
SELECT
a.update_date,
a.user_id,
a.news_id,
(CASE WHEN b.counter IS NULL THEN 0 ELSE b.counter END) as 'Counter'
FROM (
SELECT update_date, user_id, news_id
FROM t_comment
GROUP BY update_date, user_id, news_id) a
LEFT OUTER JOIN
(
SELECT update_date, user_id, news_id,
count(*) AS counter FROM t_comment
WHERE user_id = 2 AND news_id = 15
GROUP BY user_id, news_id
) b
ON a.update_date = b.update_date
AND a.user_id = b.user_id
AND a.news_id = b.news_id
GO
T-SQL实现,原理如上,未经测试。祝你好运。
a.update_date,
a.user_id,
a.news_id,
(CASE WHEN b.counter IS NULL THEN 0 ELSE b.counter END) as 'Counter'
FROM (
SELECT update_date, user_id, news_id
FROM t_comment
GROUP BY update_date, user_id, news_id) a
LEFT OUTER JOIN
(
SELECT update_date, user_id, news_id,
count(*) AS counter FROM t_comment
WHERE user_id = 2 AND news_id = 15
GROUP BY user_id, news_id
) b
ON a.update_date = b.update_date
AND a.user_id = b.user_id
AND a.news_id = b.news_id
GO
T-SQL实现,原理如上,未经测试。祝你好运。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询