how to select the min value using having key word

前端 未结 2 775
情书的邮戳
情书的邮戳 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:51
    SELECT t1.* FROM stu_dept_cs t1
    LEFT JOIN stu_dept_cs t2
    ON t1.avg > t2.avg
    WHERE t2.stu_name IS NULL;
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题