sfjordan
01-24-2006, 01:26 PM
I am trying to get mySQL to allow me to join multiple queries. Here is an example of the query that I am running:
select a.*, cnt1 from
(SELECT item_department_id totID,count(*) totCnt FROM helpdesk_items where item_created>='2006-01-01' group by item_department_id) a
left outer join (select item_department_id id1, item_calltype, count(*) cnt1 from helpdesk_items where item_created>='2006-01-01' and item_calltype=0 group by item_department_id,item_calltype) b
on totID=id1
A sample table of helpdesk_items is:
item_department_id | item_calltype
----------------------------------------------------
1 | 5
2 | 6
2 | 7
1 | 5
1 | 5
1 | 5
2 | 0
2 | 0
1 | 5
I want my results to look something like:
totID | totCnt | cnt1
-------------------------------------------------
1 | 5 | Null
2 | 4 | 2
I have done queries using this same logic on SQLServer and it works everytime. Does anyone have any idea as to what is wrong with this or how to fix it so that I can achieve the results that are listed.
select a.*, cnt1 from
(SELECT item_department_id totID,count(*) totCnt FROM helpdesk_items where item_created>='2006-01-01' group by item_department_id) a
left outer join (select item_department_id id1, item_calltype, count(*) cnt1 from helpdesk_items where item_created>='2006-01-01' and item_calltype=0 group by item_department_id,item_calltype) b
on totID=id1
A sample table of helpdesk_items is:
item_department_id | item_calltype
----------------------------------------------------
1 | 5
2 | 6
2 | 7
1 | 5
1 | 5
1 | 5
2 | 0
2 | 0
1 | 5
I want my results to look something like:
totID | totCnt | cnt1
-------------------------------------------------
1 | 5 | Null
2 | 4 | 2
I have done queries using this same logic on SQLServer and it works everytime. Does anyone have any idea as to what is wrong with this or how to fix it so that I can achieve the results that are listed.
