how to select the min value using having key word

前端 未结 2 776
情书的邮戳
情书的邮戳 2021-01-21 22:54

I have created the table stu_dep_det

CREATE TABLE  `stu_dept_cs` (
  `s_d_id` int(10) unsigned NOT NULL auto_increment,
  `stu_name` varchar(15) , `gender` varch         


        
2条回答
  •  失恋的感觉
    2021-01-21 23:58

    select somecolumn1,somecolumn2
    from stu_dept_cs 
    group by somecolumn1,somecolumn2,avg
    having avg = min(avg)
    

    or

    with t1
    (select rownumber() over (partition by somecolumn1,somecolumn2 
        order by somecolumn1,somecolumn2,avg asc) as rownum
    from stu_dept_cs )
    select * from t1 where rownum=1
    

提交回复
热议问题