group by问题
select id, JHBH, jhmc, sbdw, sbr, sbsj, state
from (select z.id, JHBH, jhmc, sbdw, sbr, sbsj, state,llrq
from mis_wz_ckd_pb z, mis_wz_ckd_xb c
where z.id = c.pbid
and c.llrq > to_date('2012-11-4', 'yyyy-mm-dd')
and c.llrq < to_date('2012-12-6', 'yyyy-mm-dd')
and c.stostore like '%'
and z.sbr like '%%'
and replace(jhbh, '-', '') like '%%'
and z.state = '2'
order by llrq)
group by id, JHBH, jhmc, sbdw, sbr, sbsj, state
括号里已经按照llrq排序了,为什么group by之后顺序又乱了呢?该如何书写?
没加GROUP BY:
加了GROUP BY:
------解决方案--------------------select id, JHBH, jhmc, sbdw, sbr, sbsj, state,llrq
from (select z.id, JHBH, jhmc, sbdw, sbr, sbsj, state,llrq
from mis_wz_ckd_pb z, mis_wz_ckd_xb c
where z.id = c.pbid
and c.llrq > to_date('2012-11-4', 'yyyy-mm-dd')
and c.llrq < to_date('2012-12-6', 'yyyy-mm-dd')
and c.stostore like '%'
and z.sbr like '%%'
and replace(jhbh, '-', '') like '%%'
and z.state = '2'
order by llrq)
group by llrq,id, JHBH, jhmc, sbdw, sbr, sbsj, state
这回试一下