SQL - How To Order Using Count From Another Table

后端 未结 6 1586
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 04:39

1. Bloggers

blogger_id
1 
2
3

2. Posts

post_from_blogger_id
1 
1
1
2
2
3

As

6条回答
  •  生来不讨喜
    2021-01-31 05:15

    I had the same problem. These answers didn't help me. I used such a query:

    SELECT *
    FROM company c
    ORDER BY (select count(a.company_id) from asset a where a.company_id = c.id) DESC
    

    To this question:

    SELECT *
    FROM bloggers b
    ORDER BY (select count(p.post_from_blogger_id) from posts p where p.post_from_blogger_id = b.blogger_id) DESC
    

提交回复
热议问题