Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 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 January 8th, 2007, 09:39 AM
Authorized User
 
Join Date: Dec 2006
Location: Texas, TX, USA.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to devendar
Default SQL Quries problem

Dear Friends,

Query for that wiil read the school12 table and tally the number of schools/district. In addition, If any school in a district has FAIL score, then the status of the distict is FAIL. populate the district table with the results.
populate the dist12 table with the results.

Thanks in advance..
Reply With Quote
  #2 (permalink)  
Old January 8th, 2007, 10:46 AM
Authorized User
 
Join Date: Dec 2006
Location: Lake Wylie, SC, USA.
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I changed the sid data in the school12 table so that we can join cleanly to the school12 table.

INSERT INTO school12 VALUES(1, 123, 'ABC','FAIL')
INSERT INTO school12 VALUES(2, 123, 'ABC1','PASS')
INSERT INTO school12 VALUES(3, 125, 'XYZ', 'PASS')
INSERT INTO school12 VALUES(4, 125, 'PQR','PASS')
INSERT INTO school12 VALUES(5, 126, 'STU', 'PASS')

One possible solution...
INSERT INTO dist12
SELECT a.did, SchoolCount, ISNULL(c.score, 'PASS')
FROM (SELECT did FROM school12 GROUP BY did) a
    JOIN (SELECT did, COUNT(sid) SchoolCount FROM school12 GROUP BY did) b ON a.did = b.did
    LEFT JOIN (SELECT did, score FROM school12 WHERE score = 'FAIL') c ON a.did = c.did

Make sure you list me on your homework as a reference... LOL


Adam Gossage
Lake Wylie, SC, USA
Reply With Quote
  #3 (permalink)  
Old January 8th, 2007, 12:37 PM
Authorized User
 
Join Date: Dec 2006
Location: Texas, TX, USA.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to devendar
Default

Dear agossage
I really appreciate your quick response.Thanks a lot. I 'll get back to you If I need more Information.
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
SQL problem MArk_dB BOOK: Beginning ASP 3.0 1 December 16th, 2007 07:33 AM
parametric quries in access rit74 VB Databases Basics 0 June 23rd, 2006 09:22 PM
SQL Problem pannet1 BOOK: Access 2003 VBA Programmer's Reference 4 April 16th, 2005 10:03 PM
SQL problem Clive Astley Access VBA 4 October 19th, 2004 10:42 AM
SQL Problem tjw Access 1 November 12th, 2003 09:22 PM



All times are GMT -4. The time now is 02:45 PM.


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