SQL对不重复项进行计数select WorkSubstance,count(Distinct Class)as Class from ClassDate where Machine='020-C03' and DateTime='2014-7-18' group by WorkSubstance此项语句是对 WorkSubstance 进行分类汇总,但WorkSubstance旁边有一列
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/28 02:08:17
SQL对不重复项进行计数select WorkSubstance,count(Distinct Class)as Class from ClassDate where Machine='020-C03' and DateTime='2014-7-18' group by WorkSubstance此项语句是对 WorkSubstance 进行分类汇总,但WorkSubstance旁边有一列
SQL对不重复项进行计数
select WorkSubstance,count(Distinct Class)as Class from ClassDate where Machine='020-C03' and DateTime='2014-7-18' group by WorkSubstance
此项语句是对 WorkSubstance 进行分类汇总,但WorkSubstance旁边有一列 CLASS ,里面可能有2种值,也可能有一种值,用这个语句进行分类汇总的时候,如果WorkSubstance是一样的,则能正确返回CLASS的不重复项个数,如果WorkSubstance是不一样的,那么就返回不了CLASS不重复项的个数,求如何能正确返回CLASS中的不重复项个数,在WorkSubstance可能是一样的也可能是不一样的情况下,
就是在分类汇总下,对符合WHERE条件下的整个一列进行不重复项计数
SQL对不重复项进行计数select WorkSubstance,count(Distinct Class)as Class from ClassDate where Machine='020-C03' and DateTime='2014-7-18' group by WorkSubstance此项语句是对 WorkSubstance 进行分类汇总,但WorkSubstance旁边有一列
那如果要不重复的,就要把分组去掉,语句改成:
select count(Distinct Class)as Class from ClassDate where Machine='020-C03' and DateTime='2014-7-18'