【发布时间】:2012-02-07 05:28:43
【问题描述】:
有两个sql查询,我想写成一个查询。 第二个查询显示不同记录的计数,其中 action_text 像 '%STAFF%'。 我尝试使用 UNION 但它不起作用。
select date(dated) date_ord,
count(DISTINCT order_number) as orders_placed,
sum(case when action_text like '%STAFF%' then 1 else 0 end) AS orders_staff,
sum(case when action_text in (
'CBA Capture attempt',
'GCO Capture attempt',
'PPP Capture',
'PPE Capture',
'Staff CC capture',
'Web CC capture',
'Staff Finance WIRE authorized',
'Staff Finance PO authorized',
'Staff Finance COD authorized',
'Authorized The CPIC') then 1 else 0 end) AS orders_manuallycaptured
from stats.sales_actions
group by date_ord
order by dated desc
SELECT COUNT(DISTINCT order_number) as unique_orderstouched,
date(dated) date_ords
FROM sales_actions
WHERE action_text like '%STAFF%'
group by date_ords
order by dated desc
【问题讨论】: