SunQuest
 
           Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

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 ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old July 24th, 2003, 03:21 AM
vals vals is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 vals User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Complex query

Hi Friends!

I have this query which will fetch count of project_ids where proj_CONFIRMED=2 and COUNTRY_ID=6. This is working abs fine. Now I need to add one more to this query. Here is my tables structure.

select count(DISTINCT Pd.Project_id) from project_master PM,PROJ_DETAILS PD where PM.mask=0 and PM.PROJECT_ID=PD.PROJECT_ID and PD.COUNTRY_ID=6 AND PM.proj_CONFIRMED=2

Here is my table design.
PROJECT_MASTER(PROJECT_ID,PROJECT_TITLE,PROJ_CONFI RMED,MASK,REGION_ID,USER_NAME)
PROJ_DETAILS(PROJECT_ID,PROJ_DETAIL,COUNTRY_ID)
COUNTRY_MASTER(COUNTRY_ID,COUNTRY_NAME,REGION_ID)
REGION_MASTER(REGION_ID,REGION_NAME)
USER_MASTER(USER_ID,USER_NAME,COUNTRY_ID)


Apart from country_id=6 I need to see if (PM.USER_NAME'S COUNTRY_ID=6 WHEN REGION_ID=4)

Please Help

Reply With Quote
  #2  
Old July 24th, 2003, 01:43 PM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
Try this. You have to join the country table with the region table. Verify that I spelled it all right!

SELECT R.REGION_NAME, COUNT(DISTINCT Pd.Project_id)
FROM project_master PM, PROJ_DETAILS PD
INNER JOIN COUNTRY_MASTER AS C
ON PD.COUNTRY_ID = C.COUNTRY_ID
INNER JOIN REGION_MASTER AS R
ON C.COUNTRY_ID = R.REGION_ID
WHERE PM.MASK=0
AND PM.PROJECT_ID=PD.PROJECT_ID
AND ( PD.COUNTRY_ID=6 AND AND R.REGION_ID = 4 )
AND PM.PROJ_CONFIRMED=2

Hope this works for you.
Danny

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Complex query


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 5 hosted by Hostway