我有日期格式问题。 以下是我的查询。 查询正在执行但没有结果。
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);
如果我执行部分工作正常,
SELECT a,b,c,DATE_FORMAT(Date_Rx_Written,'%m-%d-%Y') AS 'Date Rx Written',e,f,g,h
FROM ksclient1003.prescriber_view;
或简单地排除日期过滤器。
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);
我尝试了不同的方法,例如在我只是传递Date_RX_Written的地方更改格式。
注意:
答案 0 :(得分:0)
尝试
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';
答案 1 :(得分:0)
找到解决方案..
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);