Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a table like this

id |	park |	visitors |	date
1 |	1 |	20 | 	1/1/2014
2 |	2 |	20 |	1/1/2014
3 |	3 |	15 |	1/1/2014
4 |	4 |	13 |	1/1/2014
5 |	5 |	45 |	1/1/2014
6 |	1 |	20 |	1/1/2014
7 |	2 |	20 |	1/1/2014
8 |	3 |	15 |	1/1/2014
9 |	4 |	13 |	1/1/2014
10 |	5 |	45 |	1/1/2014
11 |	1 |	20 |	1/2/2014
12 |	2 |	20 |	1/2/2014
13 |	3 |	15 |	1/2/2014
14 |	5 |	45 |	1/2/2014


Notice: in 1/2/2014 there are not registered visitors for Park 4
I tried to do a query to show a result like this:

park |	visitors_per_day |	dateCol 
1 | 	40 |	             1/1/2014
2 |	40 |	             1/1/2014
3 |	30 |	             1/1/2014
4 |	26 | 	             1/1/2014
5 |	90 |	             1/1/2014
1 |	20 |	             1/2/2014
2 |	20 |	             1/2/2014
3 |	15 |	             1/2/2014
4 |	0 |	             1/2/2014
5 |	45 |	             1/2/2014
This is my query

select park, count(*) as visitors_per_day, dateCol from oneTable group by park, dateCol order by dateCol, park
Actually, my query does not show the Park 4 in 1/2/2014, see next example
park |  visitors_per_day |  dateCol
1 |     40 |                 1/1/2014
2 | 40 |                 1/1/2014
3 | 30 |                 1/1/2014
4 | 26 |                 1/1/2014
5 | 90 |                 1/1/2014
1 | 20 |                 1/2/2014
2 | 20 |                 1/2/2014
3 | 15 |                 1/2/2014
5 | 45 |                 1/2/2014


Is it possible to show the park 4 with a zero ?
I'm using Netezza (based on postgresql 7)
PS: sorry for my bad english... it's not my mother tongue
Posted
Updated 13-Jun-14 11:06am
v6

Dunno, but with Sql Server you can use ISNULL(COUNT(*),0)
 
Share this answer
 
Comments
bcasillas 13-Jun-14 17:08pm    
that just works if the result set, show de Park 4 with a NULL in the column visitors_per_day
the problems is "the day 1/2/2014, does not show the park 4"
thanks anymay
In complement of PIEBALD's answer, I found that could maybe be useful to you:
SO: What is the PostgreSQL equivalent for ISNULL()[^]

Unfortunately, I don't know anything, or almost, about PostgreSQL.
Good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900