MySQL Query - getting missing records when using group-by

前端 未结 4 1882
心在旅途
心在旅途 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 15:05

    Does MySQL support set-returning functions? Recent releases of PostgreSQL have a function, generate_series(start, stop) that produces the value start on the first row, start+1 on the second, and so on up to stop on the stopth row. The advantage of this is that you can put this function in a subselect in the FROM clause and then join to it, instead of creating and populating a table and joining to that as suggested by le dorfier and Bill Karwin.

提交回复
热议问题