注意事项:
1、group by 和order by 共同使用时,必须先使用group by,在使用order by
2、order by 中的字段必须是group by 中的字段
下面给出个正确的例子,这个例子是我在实习期间使用的SQL:
select count(1),no_area,sheet_type_id
from cpm_main_sheet_history
where sheet_type_id in ('905','906','901','902','903','904')
and no_area in ('0009','0001')
and end_time > '2015-01-01 00:00:00'
and end_time < '2015-02-01 00:00:00'
and is_over = '1'
group by no_area,sheet_type_id
order by no_area,sheet_type_id;