Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 11th, 2003, 01:32 PM
vjdupps vjdupps is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 16 vjdupps User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Complex SQL query - need help

Hi all,


The below is structure of my tables

table1

SurgeryDate| Surgeon1 | Surgeon2|Procedure1| Procedure2|
________________________________________________________
09/01/2003 |Ron |John | TRT | PRT
09/02/2003 |Smith |John | TRT | PRT
09/03/2003 |John | | MRT |


table2

Procedure| SurgeryType|
________________________
TRT | Ortho
PRT | General
MRT | Gyn


I worte a query as follows:
SELECT Surgeon1, SurgeryType, COUNT(*) AS 'Total Surgeries' FROM table1,tabel2 WHERE( (table1.Procedure1=table2.Procedure) AND (surgeryDate Between '09/01/2003' And '09/30/2003')) Group BY [Surg Type], [Name of Surgeon]

But this only gives me the partial total of the surgeries done by any surgeon becuase i am not including surgeon2 and procedure2. How can i reconstruct my query that gives me the total number of surgeries done by any surgeon whether his name is under surgeon1 or surgoen2 column and how can i get the count of total procedures whether it is under procedure1 or procedure2.

I am not sure whether my question is proper but i am trying to get the total count of different type of procedures done by any surgeon.

Thanks in advance.

VJ

Reply With Quote
  #2  
Old November 11th, 2003, 05:52 PM
shammat shammat is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 1,007 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 13 h 1 m 50 sec
Reputation Power: 67
This will return each surgerytype and the number of times it has been carried out. If I understood you correctly this is what you wanted (I left out the date stuff, you'll have to add it to the sub-SELECT's)

Code:
SELECT s.surgeryType,
       COUNT(*)  
FROM (SELECT t1.surgeon1 as surgeon, t2.surgerytype FROM table1 t1, table2 t2 WHERE t1.procedure1 = t2.procedure
      UNION 
      SELECT t1.surgeon2 as surgeon, t2.surgerytype FROM table1 t1, table2 t2 WHERE t1.procedure2 = t2.procedure) s
GROUP BY surgerytype


But honestly: you should rethink your DB model!

Reply With Quote
  #3  
Old November 12th, 2003, 08:20 AM
vjdupps vjdupps is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 16 vjdupps User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks a lot for your reply and suggestion.

I am sure that i have to restructure my whole DB model.

Thanks Again.

VJ

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Complex SQL query - need help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT