SQL - Displaying entries that are the max of a count?

后端 未结 7 1444
悲&欢浪女
悲&欢浪女 2020-12-01 12:35
CREATE TABLE doctor( patient CHAR(13), docname CHAR(30) );

Say I had a table like this, then how would I display the names of the doctors that have

7条回答
  •  醉话见心
    2020-12-01 13:15

    Another alternative using CTE:

    with cte_DocPatients
    as
    (
    select docname, count(*) as patientCount
    from doctor
    group by docname
    )
    select docname, patientCount from 
    cte_DocPatients where
    patientCount = (select max(patientCount) from cte_DocPatients)
    

提交回复
热议问题