我的表里有一个生日字段, 我想用一个语句求出,小于12个月的人数和所有生日不为空的人数,请问该怎么写呢?

解决方案 »

  1.   

    select birthday from yourtable t
    where t.birthday is not null
    and t.birthday<add_months(sysdate,-12)
      

  2.   

    select date
    from tab
    where date is not null 
          or 
          date < add_months(to_date(TO_CHAR(TRUNC(DATE), 'YYYY') || '01-01', 'yyyy-mm-dd'), 11)
      

  3.   

    aa 表结构 : name , birthdate 
    to Eric_1999(╙@^@╜)  :
    我要得到 用一个sql语句求出 生日小于12个月的 人数  和  全部人数
    不是要列出记录列表
    类似于这个,我觉得他太麻烦了 
    select d ,x from (
         select 
        (select count(*) from aa where birthdat is not null) d
        (select count(*) from aa where and months_between(sysdate, birthdat ) < 12) x
        from dual 
    )我知道肯定有简单的写法的,帮帮忙了
      

  4.   

    这样麻烦马?两个count(*)不同条件肯定要分开的拉!
      

  5.   

    这样简单点吧?
    select * 
    from
        (select count(*) from aa where birthdat is not null),
        (select count(*) from aa where and months_between(sysdate, birthdat ) < 12)
      

  6.   

    select count(*) from aa where birthdat is not null
    union all
    select count(*) from aa where and months_between(sysdate, birthdat ) < 12
    再简单的不好找啦