Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to write a join sql query for following conditions.

Posted on 2010-11-25
4
Medium Priority
?
160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

610 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