Postgresql选择连接按计数排序

时间:2018-04-25 19:57:47

标签: postgresql

我有两张桌子。

商品:

                          Table "public.sellers"
     Column      |           Type           |         Modifiers         
-----------------+--------------------------+---------------------------
 sellers_id      | character varying        | not null
 sellers_name    | character varying        | not null

卖家:

{{1}}

如何向卖家展示货物数量最多的请求? 谢谢。

1 个答案:

答案 0 :(得分:1)

这是sql查询:

SELECT sellers.sellers_id 
    FROM goods JOIN sellers ON goods.goods_owner_id = sellers.sellers_id
    GROUP BY sellers.sellers_id
    ORDER BY COUNT(goods.goods_id) DESC 
    LIMIT 1