Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 24th, 2005, 10:13 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old February 25th, 2005, 05:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old February 28th, 2005, 06:41 AM
Registered User
 
Join Date: Feb 2005
Location: , , .
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!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:15 PM.


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