2016-04-19 73 views
0

以下是我的查詢,我認爲原則上它應該工作,但我不知道如果它確實是可能的,或者我也在想外面這個盒子。我想分兩個選擇查詢使用SQL,不知道這是否可能

SELECT 
    (SELECT `orders`.`Status`, COUNT(*) AS COUNT_2 FROM `orders` `sw_orders` WHERE STATUS = 'booking' AND Date(OrderDate) <= CURDATE() AND Date(OrderDate) > DATE_SUB(CURDATE(),INTERVAL 30 DAY))/
    (SELECT `orders`.`Status`, COUNT(*) AS COUNT_2 FROM `orders` `sw_orders` WHERE STATUS = 'quote' AND Date(OrderDate) <= CURDATE() AND Date(OrderDate) > DATE_SUB(CURDATE(),INTERVAL 30 DAY)) 
AS result 

應該返回這裏預訂用雙引號

+0

我不是,因爲對自己的兩個主要querys,算上預訂和報價的數量在狀態欄 –

回答

1
SELECT count(case when STATUS = 'booking' then 1 end)/
      count(case when STATUS = 'quote' then 1 end) 
FROM `sw_orders` 
WHERE Date(OrderDate) <= CURDATE() 
    AND Date(OrderDate) > DATE_SUB(CURDATE(),INTERVAL 30 DAY) 
+0

我認爲,工作 –

0
select count(status ='booking' or null)/count(status = 'quote') as result from table_name where Date(OrderDate) <= CURDATE() AND Date(OrderDate) > DATE_SUB(CURDATE(),INTERVAL 30 DAY) 

分請注意語法錯誤的結果2的值。我沒有照顧。

0
SELECT 
    SUM(CASE WHEN STATUS = 'booking' THEN 1 ELSE 0 END)/
    SUM(CASE WHEN STATUS = 'quote' THEN 1 ELSE 0 END) 
FROM `sw_orders` 
WHERE Date(OrderDate) <= CURDATE() 
    AND Date(OrderDate) > DATE_SUB(CURDATE(),INTERVAL 30 DAY) 

我想STATUS =「報價」的計數不爲0

+0

似乎並沒有工作 –

相關問題