0

这是我的查询

SELECT * 
FROM tbl_djr 
WHERE 1=1 
    AND djr_date_of_work >='12/31/2012'  
    AND djr_date_of_work<='01/06/2013' 
ORDER BY djr_id 

日期格式 = m/d/Y

这是我的桌子

djr_date_of_work    djr_client_name       
01/03/2013              Maitland CC     
01/07/2013              kokil CC 
01/01/2013              Maitland CC 
01/04/2013              Maitland CC 
4

3 回答 3

2
SELECT * 
 FROM tbl_djr 
 WHERE 1=1 
  AND djr_date_of_work >='12/31/2012'  
  AND djr_date_of_work<='01/06/2013' 
ORDER BY djr_id 

上面的查询将不起作用,因为您使用了 and 条件表示 。

对于相同的条件,它应该同时满足 djr_date_of_work >='12/31/2012' 和 djr_date_of_work<='01/06/2013'

试试下面的查询

 SELECT * 
 FROM tbl_djr 
 WHERE 1=1 
  AND djr_date_of_Work between '12/31/2012'   and '01/06/2013' 
ORDER BY djr_id  

如果您的 djr_date_of_Work 是日期列,请尝试以下

 SELECT * 
 FROM tbl_djr 
 WHERE 1=1 
  AND djr_date_of_Work between TO_DATE('12/31/2012','DD/MM/YYYY') and TO_DATE('01/06/2013','DD/MM/YYYY') 
ORDER BY djr_id  
于 2013-01-07T12:37:49.170 回答
1

SQL小提琴

MS SQL Server 2012 架构设置

CREATE TABLE tbl_djr  
    (djr_id int,[djr_date_of_work] datetime, [djr_client_name] varchar(11))
;

INSERT INTO tbl_djr  
    ([djr_id],[djr_date_of_work], [djr_client_name])
VALUES
    (1,'01/03/2013', 'Maitland CC'),
    (2,'01/07/2013', 'kokil CC'),
    (3,'01/01/2013', 'Maitland CC'),
    (4,'01/04/2013', 'Maitland CC')
;

查询 1

SELECT djr_id,convert(varchar(10), djr_date_of_work, 101),djr_client_name
FROM tbl_djr
WHERE djr_date_of_work BETWEEN '12/31/2012'
    AND '01/06/2013'
ORDER BY djr_id

结果

| DJR_ID |   COLUMN_1 | DJR_CLIENT_NAME |
-----------------------------------------
|      1 | 01/03/2013 |     Maitland CC |
|      3 | 01/01/2013 |     Maitland CC |
|      4 | 01/04/2013 |     Maitland CC |
于 2013-01-07T13:14:14.347 回答
0

如果没有异常/潜在问题,这很难诊断,但是正如有人在评论中指出的那样,没有djr_id列,因此您的查询无法执行。进一步声明:

where 1=1

是无用的,因为它总是评估为真。

你想要的是像这样修改你的架构:

alter table tbl_djr add column djr_id as number

语法因您的数据库而异,但伪代码将帮助您入门。您的最终查询应如下所示:

select * from tbl_djr where djr_date_of_Work between '12/31/2012'   
and '01/06/2013' order by djr_id

作为一种风格,这个名称:
tbl_djr不提供任何信息,因为已知这djr将是一个表格。此外,所有表名都应该是复数名称,例如djrs

于 2013-01-07T12:12:47.500 回答