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

后端 未结 7 1456
悲&欢浪女
悲&欢浪女 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:09

    Take both queries and join them together to get the max:

     SELECT
          docName,
          m.MaxCount
        FROM
          author
        INNER JOIN
         (
          SELECT 
                MAX(count)  as MaxCount,
                docName
          FROM 
                (SELECT 
                      COUNT(docname) 
                 FROM 
                      doctor 
                 GROUP BY 
                      docname
                )
          ) m ON m.DocName = author.DocName 
    

提交回复
热议问题