写oracle sql挺好玩

阅读更多

select count(count_date)
  from (select to_char(b.ich_dadate, 'yyyy-mm-dd') count_date
          from ic_trnl a
         inner join ic_trnh b on b.ich_sno = a.ich_sno
         where to_char(b.ich_dadate, 'yyyy-MM-dd') between '2012-08-01' and
               '2012-08-07'
         group by to_char(b.ich_dadate, 'yyyy-mm-dd'))

结果: 6


select count(distinct to_char(b.ich_dadate, 'yyyy-mm-dd')) count_date
  from ic_trnh b
 where to_char(b.ich_dadate, 'yyyy-MM-dd') between '2012-08-01' and
       '2012-08-07'
 group by to_char(b.ich_dadate, 'yyyy-mm-dd')
 
 结果: 6 个 1
        1
        1
        1
        1
        1
        1
 
 select count(distinct to_char(b.ich_dadate, 'yyyy-mm-dd')) count_date
  from ic_trnh b
 where to_char(b.ich_dadate, 'yyyy-MM-dd') between '2012-08-01' and '2012-08-07'

结果:6
 

你可能感兴趣的:(oracle,sql,group,by,count,用法)