[英]Slightly Complicated SQL query
Write an SQL query that returns number of articles by user, as the following results with the column header: 'user_id', 'username', 'total_count_of_articles' order by number of articles编写一个 SQL 查询,按用户返回文章数,结果如下,列标题为:'user_id', 'username', 'total_count_of_articles' 按文章数排序
Something like this should return the specified resultset:这样的事情应该返回指定的结果集:
SELECT u.id AS user_id
, u.user_name
, SUM(a.user_id IS NOT NULL) AS total_count_of_articles
FROM users u
LEFT
JOIN users_articles a
ON a.user_id = u.id
GROUP BY u.id, u.user_name
ORDER BY total_count_of_articles DESC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.