有一个表如下所示:table 表id name date
1 anne 2005-09-12 00:00:00.000
2 winnie 2005-10-01 00:00:00.000
3 annea 2005-09-09 00:00:00.000
4 wine 2005-10-06 00:00:00.000现在得出其date为 2005-09 的纪录,这条SQL要怎么写?请教各位!

解决方案 »

  1.   

    mysql里面
    select * from tableName
    where date like '2005-09%'
    可以其他函数不是很清楚,好像不同的数据库有不同的操作方式
      

  2.   

    select * from tableName
    where left(date,7)='09 2005'
      

  3.   

    我的是SQLserver的,上面那个不能
      

  4.   

    哪个不能啊?如果 date 是字符串类型(不是时间/日期类型),迷失的代码在 SQL Server 上绝对不会有问题。
      

  5.   

    select * 
    from table
    where datediff(month,date,'2005-9-1')=0;9-1还可以是9月1~31任意值。
      

  6.   

    select * from anne where datepart(mm,date)=9

    select * from anne where substring(convert(varchar(10),[date],120),6,2)='09'
      

  7.   

    可用 believefym的方式,like 是sql 92标准语.一般数据库都支持
      

  8.   

    我想请问一下其中那个convert怎么用?那么是什么意思?为什么里面的数据换了就不能得到所要的结果了?
      

  9.   

    in sql server:
    select * from tableName
    where date='2005-09'
      

  10.   

    select * from tableName
    where date>='2005-09-01' and date<='2005-09-31'
      

  11.   

    9月只有30天,呵呵
    select * from tableName
    where date>='2005-09-01' and date<'2005-09-31'
      

  12.   

    select * from tableName
    where date>='2005-09-01' and date<='2005-09-30'