日期:2014-05-18 浏览次数:20603 次
select top 10000 sc.subjectsClassname,s.subjectname,count(s.subjectname) as Num,A.teacherID,tp.jobcategory1 from BI_SubjectLessonForSalary as A left join BI_subjects s on A.subjectID=s.subjectID left join Bi_subjectsClass sc on A.subjectsClassID=sc.subjectsClassID left join Tm_TeacherProfile tp on A.teacherID=tp.ID1 where A.TeacherID is not null and A.teacherID>0 group by s.subjectname,sc.subjectsClassname,A.teacherid,tp.jobcategory1
--按什么分组就group by 什么就可以了 select top 10000 min(sc.subjectsClassname)subjectsClassname ,s.subjectname,count(s.subjectname) as Num, min(A.teacherID)teacherID, min(tp.jobcategory1) jobcategory1 from BI_SubjectLessonForSalary as A left join BI_subjects s on A.subjectID=s.subjectID left join Bi_subjectsClass sc on A.subjectsClassID=sc.subjectsClassID left join Tm_TeacherProfile tp on A.teacherID=tp.ID1 where A.TeacherID is not null and A.teacherID>0 group by s.subjectname
------解决方案--------------------
你group by 后面有4个字段,所以出现上述结果是没有问题的。
------解决方案--------------------
A.teacherid,tp.jobcategory1 --你有4个字段,Groupby 就是要求你4个字段的组合都相同的,这4个字段只要有1个不相同就会是新的一组了。比如:AAAA与ABAA,这就是2组。
------解决方案--------------------
语法没有任何问题,按照楼主目前得到的结果,需要最终正确数据集是什么样的?