MySQL Query - getting missing records when using group-by

前端 未结 4 1880
心在旅途
心在旅途 2021-01-07 14:48

I have a query :

select score, count(1) as \'NumStudents\' from testresults where testid = \'mytestid\'
group by score order by score

4条回答
  •  礼貌的吻别
    2021-01-07 14:50

    Just as a mental exercise I came up with this to generate a sequence in MySQL. As long as the number of tables in all databases on the box squared are less than the total length of the sequence it will work. I wouldn't recommend it for production though ;)

    SELECT @n:=@n+1 as n from (select @n:=-1) x, Information_Schema.Tables y, Information_Schema.Tables WHERE @n<20; /* sequence from 0 to 20 inclusive */
    

提交回复
热议问题