SQL select MAX(COUNT)

后端 未结 5 906
梦如初夏
梦如初夏 2021-01-18 03:54

I\'m trying to select the user who has the MAX microposts count:

SELECT \"name\", count(*) FROM \"users\" 
  INNER JOIN \"microposts\" ON \"microposts\".\"us         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 04:40

    It's pretty simple, you can try:

    SELECT "name", MAX(count_num) FROM 
    (SELECT "name", count(*) as count_num
    FROM "users" INNER JOIN "microposts" ON "microposts"."user_id" = "users"."id"
    GROUP BY users.id) x
    

提交回复
热议问题