我試圖裝置激勵計劃,根據訂單的數量我的代理銷售,並轉移他們的工作。獲取特定計數Mysql的使用情況/如果
的sales
表(MySQL的)具有以下列:
sale_id (int, primary, auto increment)
employee (varchar, 255)
sale_time (datetime, the time sale was placed)
sale_amount (float 10,2)
sales_channel (tinyint, with values call (1), walk_in (2),referral(3))
is_cancelled (tinyint, with values 1 for cancelled, and 0 as default)
(and a few other columns that are not relevant for this case)
我想要編寫一個查詢來獲取與下面的列(我用的訂單和銷售互換)的結果:
employee
total_orders (count excluding cancelled sales, i.e. is_cancelled!= 1)
orders_below_100dollars (orders count with sale_amount below 100 and is_cancelled = 0)
orders_above_100dollars (orders count with sale_amount above 100 and is_cancelled = 0)
orders_dayShift (orders count placed between 9am and before 10pm and is_cancelled = 0)
orders_nightShift (orders count placed after 10pm and before next day 9am and is_cancelled = 0)
cancelled_orders (orders count with is_cancelled = 1)
我明白是t他的查詢將有group by
,case
和if/else
在選擇,但不能正確框架。請幫忙。
你沒有,如果total_orders和orders_below精確等應包含在每個類別或金額的訂單數量總計。 –
將編輯感謝。我的意思是伯爵。 –