Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 查找与今天相关的记录_Sql - Fatal编程技术网

Sql 查找与今天相关的记录

Sql 查找与今天相关的记录,sql,Sql,我有一个名为dbstorage的表,其中有year和weekno等列 我需要选择小于当前年度和当前周的年度和周 我用过: select * from dbstorage where year<=2011 and weekno<=13. 从dbstorage中选择*年您可以将其分为两种情况并使用或 SELECT * /*<-- But don't use * List the columns explicitly*/ FROM dbstorage WHERE ( year

我有一个名为
dbstorage
的表,其中有
year
weekno
等列

我需要选择小于当前年度和当前周的年度和周

我用过:

select * from dbstorage where year<=2011 and weekno<=13.

从dbstorage中选择*年您可以将其分为两种情况并使用

SELECT * /*<-- But don't use * List the columns explicitly*/
FROM   dbstorage
WHERE  ( year = 2011
         AND weekno <= 13 )
        OR year < 2011  

您必须将搜索分成多个部分:

select * from dbstorage 
where
    (year = 2011 and weekno <= 13) -- will catch all weeks in 2011 PRIOR to this one
    or (year < 2011) -- will catch all weeks in 2010 and earlier
从数据库存储中选择*
哪里

(year=2011和weekno对于SQL Server,您还可以执行以下操作:

SELECT *
FROM dbstorage
WHERE (year = DATEPART(yyyy, GETDATE())
      AND weekno <= DATEPART(ww, GETDATE()))
OR year < DATEPART(yyyy, GETDATE())
选择*
从数据库存储
其中(year=DATEPART(yyyy,GETDATE())
还有威克诺
SELECT *
FROM dbstorage
WHERE (year = DATEPART(yyyy, GETDATE())
      AND weekno <= DATEPART(ww, GETDATE()))
OR year < DATEPART(yyyy, GETDATE())