MSSQL?fbirthday是DATETIME 型?select fempname
from t_emp
where fbirthday between cast(cast(year(fbirthday) as varchar(4))+'-09-01' as datetime) 
and cast(cast(year(fbirthday) as varchar(4))+'-12-15' as datetime) 

解决方案 »

  1.   

    sql server
    select * from TableName where (datepart(month,BIRTHDAY)>9 and datepart(month,BIRTHDAY)<12)
    or (datepart(month,BIRTHDAY)=12 and datepart(day,BIRTHDAY)<=15)别的数据库也有类似写法,以后别把这个当难题!
      

  2.   

    SORRY,没有表达清楚,假如我的生日是1971-10-13,现在我要知道所有生日期间在9-1和12-15日期间年纪比我大的人数,即有1921-10-8,1921-10-8,1978-10-2,1978-10-2 ,1981-10-5
    这些人
    然后是列表:和我一样大的人数: 生日 
               1      1921-10-8
               1      1921-10-8
               0      1978-10-2
               1      1978-10-5
               1      1978-10-5
               0      1981-10-5     
    这是一个CRM中的客户关系模块,我怎么用一个语句实现不了呢? 
               
      

  3.   

    说一下这个存储过程的具体要求了,是传入两个日期型(客户的变态要求即然是按生日还要输入日期)参数,然后根据这两个参数来列出所有的列表(还要一个比我大的人数呀),即列表为
    和我一样大的人数   生日         比我大的人数
    各位帮忙了,分数绝对不会少的了,我还有统计查询分析都没有做呀,没有办法了,各位GG跟JJ多帮帮忙呀 
      

  4.   

    Oracle
    select *
    from TableName 
    where to_char(BIRTHDAY,'mm-dd') between '09-01' and '12-15'
      

  5.   

    你的列表什么意思?完全看不懂,按照你的文字描述,只需要这么写:
    select count(*) from [table] where substring(convert(varchar(32), birthday, 102), 6, 5) between '09.01' and '12-15' and substring(convert(varchar(32), birthday, 102), 1, 4) < '1971'
      

  6.   


    多加一个where条件就是了.
      

  7.   

    TO MINYIBO,用文字排序好象不行呀,因为9肯定是排在1后面的呀,而且客户他的输入不是规范的,他的日期格式可以为2001-9-1,不是以零开头的呀
      

  8.   

    TO HAIWER:和我一样大表示是同年同月同日呀,因为涉及到要建立客户生日档案所以要这样做
      

  9.   

    TO GodHack: 你的生日字段难道不是DateTime类型吗?
      

  10.   

    TO progame, 别瞎起哄,有本事就赶紧写出你的答案来!
      

  11.   

    兄弟们,恕我语文水平很差,不知道我现在的头有多晕呀,任务重如山呀!FAINT~~~~~~帮我搞定吧!问题是这样的,假如在公司客户档案中,我现在要查出所有的其生日在9-1和12-15号的客户并且我想知道有与之相同生日的人有多少(即年月日都相同),还有比他年龄大的有多少人(因为要进行客户年龄范围的数据分析),
    假设客户数据为
    客户ID        客户生日
    1             1975-9-1
    2             1976-8-27
    3             1981-10-9
    4             1975-9-3
    5             1977-9-20
    6             1981-10-9
    7             1981-10-10
    即要求的打印列表为
    客户ID   客户出生日期       与之年龄相同的客户人数    比其年龄大的客户人数
    1        1975-9-1             0                        0
    4        1975-9-3             0                        1
    5        1977-9-20            0                        2
    3        1981-10-9            1                        3
    6        1981-10-9            1                        3
    7        1981-10-10           0                        5
    客户2             1976-8-27由于不满足9-1--12-15的条件所以不能在列表中请问用一条语句如何实现这个列表,还有一个半小时要下班了,完不成的话明天要来加班,可是明天我有课要上呀!惨呀惨
      

  12.   

    select cust_id, birthday,
          (select count(*)
             from customer
            where birthday = x.birthday) countOfSameBirthdy,
          (select count(*)
             from customer
            where birthday > x.birthday) countOfOlder
      from customer x
     where to_char(birthday,'MM-DD') between '09-01' and '12-15'
      

  13.   

    是ORACLE PL/SQL语法的,在O8.16上通过那位兄弟把这段改成T-SQL?
      

  14.   

    还是沿用我刚才的用DATEPART的写法,有一个好处:6.0都能用.select 客户ID,客户生日,
    (select count(*) 
    from 客户数据 
    where 客户id<>a.客户Id 
    and 客户生日=a.客户生日) as 与之年龄相同的客户人数,
    (select count(*) 
    from 客户数据 
    where ((datepart(month,客户生日)>9 and datepart(month,客户生日)<12)
    or (datepart(month,客户生日)=12 and datepart(day,客户生日)<=15))
    and 客户生日<a.客户生日
    ) as 比其年龄大的客户人数
     from 客户数据 a
    where (datepart(month,客户生日)>9 and datepart(month,客户生日)<12)
    or (datepart(month,客户生日)=12 and datepart(day,客户生日)<=15)
      

  15.   

    啊呀有点问题,看了Haiwer(海阔天空)才明白过来.我写的SQL要在COUNT(*)后面减去一,象这样:
    select cust_id, birthday,
          (select count(*) - 1
            from customer
            where birthday = x.birthday) countOfSameBirthdy,
          (select count(*) -1
            from customer
            where birthday > x.birthday) countOfOlder
      from customer x
    where to_char(birthday,'MM-DD') between '09-01' and '12-15'
      

  16.   

    SELECT Text5,OrderDate,
    (SELECT COUNT(*) From Orders WHERE Orders.OrderDate=x.OrderDate) AS 相同生日 ,
    (SELECT COUNT(*) From Orders WHERE Orders.OrderDate>x.Orderdate  ) AS 大於生日的人數 
    From Orders x 
    WHERE ORderDate between cast(cast(year(OrderDate) as varchar(4))+'-09-01' as datetime) 
    and cast(cast(year(Orderdate) as varchar(4))+'-12-15' as datetime) 
      

  17.   

    to google_real:公司给的压力,不然高手就不会出手了,呵呵,刚刚拜读了PROGMAN的灌水手册