|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SIMILAR probs
Hi
I have similar problem and i explained in detail here http://www.balainfo.com/forums/viewtopic.php?t=39 Pls help me to fix this sql Regds Bala |
|
#2
|
||||
|
||||
|
it is considered bad etiquette to (1) ask a new question by posting onto an existing unrelated thread, and (2) ask people to leave devshed to visit some other site
your problem is that your two relationships are totally unrelated to each other, consequently any grouping query is going to have cross join effects your solution is: Code:
select EMP.id as [ID]
, EMP.empname as [Name]
, count(EMP_appreciation.sal) as [No. Bonus]
, max(EMP_appreciation.sal) as [Max Bonus]
, ( select count(eid)
from EMP_projects
where eid = EMP.id ) as [Projects Count]
from EMP
left outer
join EMP_appreciation
on EMP.id
= EMP_appreciation.eid
group
by EMP.id
, EMP.empname
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > aggregates from two unrelated tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|