Home > database >  The problem how to use SQL statements at most 7 said ah.. meng
The problem how to use SQL statements at most 7 said ah.. meng

Time:10-25

Topic, one's deceased father grind, who help me Chou Chou

CodePudding user response:

The select G.S no, count (*) as the from CNT G
The join S on G.S no=S.S no
Group by G.S no
The order by CNT desc
Limit 1

CodePudding user response:

Select Sno, count (*) from S
Group by 1 order by 2 desc
LIMIT 1

CodePudding user response:

Most of the students as the number of times may have multiple?

CodePudding user response:

Select Sno, count (*) as the from CNT G
Group by Sno
The order by CNT desc
Limit 1

If there are multiple times as students, also can only select one

CodePudding user response:

If considering the maximum have more than one can use the following syntax
SELECT
Sno, COUNT (Sno) AS cou
The FROM
G
GROUP BY Sno
HAVING cou=(SELECT
COUNT (Sno) AS cou
The FROM
G
GROUP BY Sno
The ORDER BY cou DESC
LIMIT 1)
  • Related