Solved

How to write a join sql query for following conditions.

Posted on 2010-11-25
4
155 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CREATE DATABASE ENCRYPTION KEY 1 82
upgrade sql 2005 32bit to sql 2008 32 or 64bit on a server 2008 r2 box 6 99
Restrict result set 1 48
Sql query 107 100
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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