Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested SQL Queries to achieve this?

Status
Not open for further replies.

esemerda

Programmer
Feb 24, 2005
3
AU
Here's my dummy table:
page ip mark
pageA 127.0.01 n
pageA 127.0.01 c
pageB 128.42.52 n
pageB 128.42.52 c
pageB 128.42.52 c
pageB 328.3.11 n
pageB 328.3.11 c
pageC 228.2.01 n

i'd like to run a count(distinct ip), group by page but also be able to
extract how many distinct by page using the mark column where char ='n'.

ie. i need 1 sql statement which will pump the following out;

page count(ip) count(mark)
pageA 2 1
pageB 3 2
pageC 1 1

total 6 4

any ideas?
Cheers,
Ernest
 
Code:
select page,count(distinct ip) as countIP,
 sum(case when mark = 'n' then 1 else 0 end) as countMark
from t
group by page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top