Solved

How to write a join sql query for following conditions.

Posted on 2010-11-25
4
153 Views
Last Modified: 2012-08-14
1.Table 1
Txnenrollment contains familyid,enrolled,cardsprinted,personalized,pcode,blockcode.
2.Table 2
Txnissuance contains those familyid which will be there in txnenrollment
and will have status enrolled=1 and personalized=1 and cardsprinted=1
3.Table 3
mstpanchayat will contain pcode and pname
4.Table 4
mstblock will contain blockcode and blockname
I want to list blockname,pname and count of total enrolled,total personalized and total cardsprinted with a check where all familyid should exist in txnissuance.
0
Comment
Question by:searchsanjaysharma
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Andre412
ID: 34214018

Can you give more information about the relationships between the tables
0
 
LVL 6

Accepted Solution

by:
rkannan2000 earned 500 total points
ID: 34214310
This might help you....

SELECT D.BLOCK_NAME, C.PNAME, SUM(A.ENROLLED),SUM(A.PERSONALIZED),SUM(A.CARDHOLDER), COUNT(A.FAMILY_ID)-COUNT(B.FAMILY_ID)
FROM Txnenrollment A
LEFT OUTER JOIN Txnissuance B ON A.FAMILY_ID=B.FAMIL_ID
JOIN mstpanchayat C ON C.PCODE=A.PCODE
JOIN mstblock D ON D.BLOCKCODE=A.BLOCKCODE
GROUP BY D.BLOCK_NAME, C.PNAME
0
 

Author Comment

by:searchsanjaysharma
ID: 34215298
pcode is primary key in mstpanchayat,
blockcode is primary key in mstblock
and pcode and blockcode exists in txnenrollment
and txnissuance will have only those familyid
which will exist in txnenrollment and will have status of enrolled=1 and personalized=1 and cardsprinted=1
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37767131
ok
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question