總數我有得到員工的總數與交易
employeeid, country, state, and city
一個員工表以後,我的交易表
transaction_id, employeeid, transaction-details
所以我需要
country state city total(no_of_employee), count(transactions), count(no_of_employee_done_transaction)
我已經嘗試並能夠獲得
country state city count(transactions), count(no_of_employee_done_transaction)
通過使用此查詢:
select em.Country, em.state, em.city , count(transaction_id) as "count(transaction)" , count(distinct(employeeid)) as "count(number of employee done transaction)"
from transaction tr
right outer join employee em on tr.employeeid = em.employeeid
where to_char(tran_date,'Mon-YYYY')='Jun-2014'
group by em.country,em.state, em.city;
,如果我把count(employee_id)
在選擇列表中,然後它總是等於count(transaction_id)
什麼修改上面的查詢,實現count(employee_id)
。
請提供樣品表數據和所需結果。 – 2014-09-02 10:39:34
即你想從每個城市的交易表中獲得兩個不同的計數?我不認爲你可以在沒有子查詢或CTE或類似的單個查詢中做到這一點。 – Rup 2014-09-02 10:42:15
您是否嘗試過COUNT(DISTINCT CASE WHERE transaction_id不爲NULL then employeeid)AS「count(no_of_employee_done_transaction)」 – scragar 2014-09-02 10:43:05