oracle sql查询返回没有行

时间:2017-05-10 05:11:10

标签: mysql sql oracle11g oracle-sqldeveloper

我有两个表customer和customerType。我想从customerType表中获取VVIP客户的数量,其预订日期为2016年1月24日至2016年1月27日。 我的问题:

select count(distinct f.CUSTOMER_ID) as agg from customerType f JOIN 
customer t ON f.CUSTOMERID=t.CUSTOMERID where 
f.type='VVIP' and t.BookingDate BETWEEN 
TO_DATE('10/01/2016','MM/DD/YYYY') AND TO_DATE('10/02/2016','MM/DD/YYYY');

enter image description here

4 个答案:

答案 0 :(得分:0)

select count(distinct f.CUSTOMER_ID) as agg from customerType f 
INNER join JOIN customer t ON f.CUSTOMERID=t.CUSTOMERID where 
f.type='VVIP' and t.BookingDate BETWEEN 
TO_DATE('01/24/2016','MM/DD/YYYY') AND TO_DATE('01/27/2016','MM/DD/YYYY');

尝试以上查询。

希望这会有所帮助。

答案 1 :(得分:0)

基本上我正在使用mysql,但是mysql,oracle之间没有太大的区别所以请尝试下面的查询,这将有力地帮助你

index.js

它会起作用请尝试

答案 2 :(得分:0)

这样做: -

To_DATE放在column name上,而不是放在值

   Select count(distinct f.CUSTOMER_ID) as agg from customerType f 
   INNER JOIN 
   customer t ON f.CUSTOMERID=t.CUSTOMERID where 
   f.type='VVIP' and (TO_DATE(t.BookingDate,'MM/DD/YYYY') BETWEEN 
   '10/01/2016' AND '10/02/2016');

答案 3 :(得分:0)

试试这个:

SELECT count(DISTINCT t.customerid) AS agg
FROM customer t
LEFT JOIN customertype f
ON f.customerid=t.customerid
WHERE f.TYPE   ='VVIP'
AND to_date(t.bookingdate,'MM/DD/YYYY') BETWEEN to_date('01/24/2016','MM/DD/YYYY') AND to_date('01/27/2016','MM/DD/YYYY');
相关问题