关于sum和having,得出having sum(a)> 123的总数 语句问题
SELECT thename,sum(thescore) FROM name_subject_score GROUP BY thename HAVING SUM(thescore) > 186
先算出sum的值,在在having中进行筛选,得出结果
SELECT thename,COUNT(1) FROM name_subject_score GROUP BY thename HAVING SUM(thescore) > 186
count(1) 是以thename进行分组,得出每个人有多少科.在进行having筛选.
SELECT COUNT(1) FROM (SELECT COUNT(1) FROM name_subject_score GROUP BY thename HAVING SUM(thescore) > 186 )
直接数数了得出结果
= = 感觉怪怪的呢?怎么得出结果直接为2?
这是select * 的结果
这是SELECT thename, SUM(thescore) FROM name_subject_score GROUP BY thename
就是怎么写出总分大于186的总人数.还有我以上的想法(橙色部分)对吗?
Oracle语句
------解决方案--------------------感觉怪怪的呢?怎么得出结果直接为2?
count(1)统计的是SELECT thename,COUNT(1) FROM name_subject_score GROUP BY thename HAVING SUM(thescore) > 186 结果集的行数,当然为2.
你上面不是已经写出来总分数大于186 的人数了吗
------解决方案--------------------结果不对吗?不就那两个吗?