简体   繁体   English

查询没有给出期望的结果

[英]query is not giving desired result

I have date format issue. 我有日期格式问题。 Below is my query. 以下是我的查询。 Query is executing but without result. 查询正在执行,但没有结果。

SELECT a,b,c,DATE_FORMAT(Date_Rx_Written,'%m-%d-%Y') AS 'Date Rx Written',e,f,g,h 
FROM ksclient1003.prescriber_view 
WHERE DATE_FORMAT(Date_Rx_Written,'%m-%d-%Y')
BETWEEN coalesce(NULLIF('11-11-2008',' '),Date_RX_Written)
AND coalesce(NULLIF('11-11-2016',' '),Date_RX_Written) 
AND a=coalesce(NULLIF('Genene Radden',' '),a) 
AND b=coalesce(NULLIF('Filled',' '),b);

if i execute in parts it is working fine like, 如果我执行部分工作,就像,

SELECT a,b,c,DATE_FORMAT(Date_Rx_Written,'%m-%d-%Y') AS 'Date Rx Written',e,f,g,h
FROM ksclient1003.prescriber_view;

or simply excluding date filter. 或仅排除日期过滤器。

SELECT a,b,c,DATE_FORMAT(Date_Rx_Written,'%m-%d-%Y') AS 'Date Rx Written',e,f,g,h
FROM ksclient1003.prescriber_view 
WHERE a=coalesce(NULLIF('Genene Radden',' '),a)
AND b=coalesce(NULLIF('Filled',' '),b);

i have tried different approach like changing format every place where i am simply passing Date_RX_Written. 我尝试了不同的方法,例如在我只是传递Date_RX_Written的每个地方更改格式。

Note : 注意 :

Try 尝试

SELECT 
   a, b, c, 
   DATE_FORMAT(Date_Rx_Written,'%m-%d-%Y') as 'Date Rx Written',
   e,f,g,h 
FROM ksclient1003.prescriber_view 
WHERE 
   Date_Rx_Written BETWEEN '2008-11-11' AND '2016-11-11' 
   AND a='Genene Radden' 
   AND b='Filled';

找到了解决办法..

select a,b,c,DATE_FORMAT(Date_Rx_Written,"%m-%d-%Y") as 'Date Rx Written'  ,d,e,f,g from ksclient1003.prescriber_view  WHERE Date_Rx_Written BETWEEN coalesce(NULLIF(STR_TO_DATE('31-12-2014' , "%d-%m-%Y"),' ')) and coalesce(NULLIF(STR_TO_DATE('31-12-2016' , "%d-%m-%Y"),' ')) and a=coalesce(NULLIF('Genene Radden',' '),a) and b=coalesce(NULLIF('Filled',' '),b);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM