之后:
SELECT forum_categories.id AS category_id, forum_categories.title, forum_topics.id AS topic_id, forum_topics.title, user
FROM forum_categories JOIN forum_topics ON forum_categories.id=forum_topics.category_id
LEFT OUTER JOIN forum_views ON forum_topics.id=forum_views.topic_id
WHERE forum_categories.id=6
ORDER BY forum_categories.id
我得出以下结果:
现在我要:
- add another field in the select, called thereIsANull
- group all my results by the field
usercategory_id - setting thereIsANull to 1 if there isn t a NULL in the field user (while grouping), 0 otherwise.
因此,如下文所示,结果必须是一行:
6 Welcome (some topic_id) (some title) (djfonplaz or null) 0
并且,如果所有用户都不同于NCL :
6 Welcome (some topic_id) (some title) (djfonplaz) 1
我如何能够在我的Sql上这样做?