Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 24th, 2005, 10:13 PM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Plz Help - Nested SQL Statements?

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

 
Old February 25th, 2005, 05:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think this will do it:
Code:
SELECT page, 
       COUNT(ip) AS count_ip,
       SUM(CASE WHEN mark='n' THEN 1 ELSE 0 END) AS count_mark
FROM <<table>>
GROUP BY page
 
Old February 28th, 2005, 06:41 AM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by pgtips
 I think this will do it:
Code:
SELECT page, 
       COUNT(ip) AS count_ip,
       SUM(CASE WHEN mark='n' THEN 1 ELSE 0 END) AS count_mark
FROM <<table>>
GROUP BY page
Thank you pgtips. It worked well!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Mulitiple/Nested IIF statements rohit_ghosh Access VBA 3 June 1st, 2007 10:44 AM
Can i use asp within sql statements knight Classic ASP Databases 43 May 24th, 2007 09:32 AM
CASE Statements in T-SQL atcs2152 SQL Server 2000 3 April 28th, 2006 10:53 AM
Ho to do nested if statements scoobie PHP How-To 2 April 24th, 2005 06:22 AM
SQL Statements marmer Classic ASP Basics 3 November 13th, 2003 01:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.