表:list
字段:user_id,time(日期),barcode
我想实现这样的查询: user_id = '001' 的用户,他2008年11月份,每天共有多少条记录!怎么写呢? 

解决方案 »

  1.   

    select user_id, to_char(time, 'yyyy-mm-dd'), count(*)
      from list
     where to_char(time, 'yyyy-mm') = '2008-11'
     group by to_char(time, 'yyyy-mm-dd');
      

  2.   

    select user_id,to_char(time,''yyyy-mm-dd'),count(*) from list 
     where user_id = '001' and to_char(time,'yyyy-mm') = '2008-11' 
    group by user_id,to_char(time,'yyyy-mm-dd')
      

  3.   

    select user_id, to_char(time, 'yyyy-mm-dd'), count(*)
      from list
     where to_char(time, 'yyyy-mm') = '2008-11'
       and user_id = '001'
     group by to_char(time, 'yyyy-mm-dd');
      

  4.   

    select count(barcode)
    from list
    where user_id = '001'
    and to_char(time,'yyyy-mm') = "2008-11"
    group by to_char(time,'yyyy-mm-dd');应该是这样的!觉得能实现你说的那个功能!