做个本月下载榜的功能
我得首先取得现在的年月份,之后和数据库中DATE字段比较,这个比较的过程用SQL语句怎么写?DATE字段中也有年月份,也有日期,连在一起的。

解决方案 »

  1.   

    Give out some sample data first
      

  2.   


    select 日期,下载次数 from @t where year(日期)=year(getdate()) and month(日期)=month(getdate())
    orselect 日期,下载次数 from @t where convert(nvarchar(7),日期,120)=convert(nvarchar(7),getdate(),120)
      

  3.   

    --with a datetime column(or a string column has data like '2006/7/26')select * from tablename
    where datediff(month,columnname,getdate())=0
      

  4.   

    这个下载榜就是在网页中显示本月下载排行,要求里面显示的是从每个月的月初到现在的时间根据下载次数倒序排列。two column the name of date  and hits
    the column of  date ,in it date like this: 2001-10-12 17:03:54forexample: 
    现在网页中显示的应该是7月份的下载排行,所以我想先通过日期函数取得现在的年份月份,再从数据库中相同的年份和月份的hits字段中倒序排列,这个判断现在的日期和数据库中从这种日期显示方式:2001-10-12 17:03:54 数据取得年份和月份的方法我不太会。
    我是个新手,初学,大家不要见笑,谢谢楼上两位仁兄的帮助,我再试一下楼上两位的方法。
    还有一个问题就是怎么去统计数据库中一共有多少条数据?
      

  5.   

    The field hits is not needed here.Just use this query can get data of this month
    select * from tablename
    where datediff(month,[date],getdate())=0for detail about datediff function,please look it up on the Books online
      

  6.   

    还有一个问题就是怎么去统计数据库中一共有多少条数据
    --------------------------------------
    You can use count() to get total data stored in the table