There are four areas in my compay: E, W, S, N.
When I use aggregate function to count to order number of each area, there
maybe some area disappear
in the result, like
select Area, Count(*) from orders
Area OrderCount
E 12
W 15
N 14
But I want to result to
Area OrderCount
E 12
W 15
S (null or 0)
N 14
How can I do?
select A.Area, Count(*)
from orders O
LEFT JOIN Areas A
ON A.Area = O.Area
That should help.
Jens Suessmeyer.
Showing posts with label disappearin. Show all posts
Showing posts with label disappearin. Show all posts
Monday, March 19, 2012
How to add the lost keys
There are four areas in my compay: E, W, S, N.
When I use aggregate function to count to order number of each area, there
maybe some area disappear
in the result, like
select Area, Count(*) from orders
Area OrderCount
--
E 12
W 15
N 14
But I want to result to
Area OrderCount
--
E 12
W 15
S (null or 0)
N 14
How can I do?select A.Area, Count(*)
from orders O
LEFT JOIN Areas A
ON A.Area = O.Area
That should help.
Jens Suessmeyer.
When I use aggregate function to count to order number of each area, there
maybe some area disappear
in the result, like
select Area, Count(*) from orders
Area OrderCount
--
E 12
W 15
N 14
But I want to result to
Area OrderCount
--
E 12
W 15
S (null or 0)
N 14
How can I do?select A.Area, Count(*)
from orders O
LEFT JOIN Areas A
ON A.Area = O.Area
That should help.
Jens Suessmeyer.
Subscribe to:
Posts (Atom)