sql查找最新上架(为本月前20天)语句要怎么写,字段newsTime(datetime)

解决方案 »

  1.   

    select top 20 * from 表 where convert(varchar(7),newsTime,120)=convert(varchar(7),getdate(),120)
      

  2.   

    忘了order by 了
    select top 20 * from 表 where convert(varchar(7),newsTime,120)=convert(varchar(7),getdate(),120)
    order by newsTime desc
      

  3.   

    select * from Table where [newsTime]< convert(datetime,convert(nvarchar(8),getdate(),120)+'20')
      

  4.   

    select * from 表名 where convert(varchar(7),newsTime,120)=convert(varchar(7),getdate(),120) and day(newsTime)<20 
      

  5.   

    select * from 表名 where convert(varchar(7),newsTime,120)=convert(varchar(7),getdate(),120) and day(newsTime)<20 
      

  6.   

    select * from 表 where convert(varchar(7),newsTime,120)=convert(varchar(7),
    getdate(),120) and day(newsTime)<21 
      

  7.   

    select * from 表 where 
    datediff(dd,newsTime,getdate())<20
      

  8.   

    select * from table where newsTime between convert(char(4),year(getdate()))+ '-'+convert(char(2),Month(getdate()))+'-01' and convert(char(4),year(getdate()))+ '-'+convert(char(2),Month(getdate()))+'-20'
      

  9.   

    select * from Table where [newsTime]< convert(datetime,convert(nvarchar(8),getdate(),120)+'20')楼上的这条数据全部把所以的数据都查出来了,没有用
      

  10.   

    select * from tb where newsTime between  DATEADD(mm,DATEDIFF(mm,0,getdate()),0) 
    and  DATEADD(d,20,DATEADD(mm,DATEDIFF(mm,0,getdate()),0))