Wrox Programmer Forums
|
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 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 January 8th, 2007, 09:39 AM
Authorized User
 
Join Date: Dec 2006
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..
 
Old January 8th, 2007, 10:46 AM
Authorized User
 
Join Date: Dec 2006
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
 
Old January 8th, 2007, 12:37 PM
Authorized User
 
Join Date: Dec 2006
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.





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





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