Solved

continue - Subtypes count

Posted on 2009-07-08
2
165 Views
Last Modified: 2012-05-07
See related question.

How would I return 1 row with all the subtypes.  
The return row should be:
Id, T1S1, T1S2, T1S3, T2S1,T2S2,T2S3
T1S1 means Type=1 SubType=1, T2S1 means Type=2 and SubType=1 etc.
T1S1,T1S2... should show how many subtypes exist.
0
Comment
Question by:johnkainn
2 Comments
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 24802355
Hope this helps
SELECT ID, sum( CASE WHEN Type=1 AND SubType=1 THEN 1 ELSE 0 END) T1S1,

sum( CASE WHEN Type=1 AND SubType=2 THEN 1 ELSE 0 END) T1S2,

sum( CASE WHEN Type=1 AND SubType=3 THEN 1 ELSE 0 END) T1S3,

sum( CASE WHEN Type=2 AND SubType=1 THEN 1 ELSE 0 END) T2S1,

sum( CASE WHEN Type=2 AND SubType=2 THEN 1 ELSE 0 END) T2S2,

sum( CASE WHEN Type=2 AND SubType=3 THEN 1 ELSE 0 END) T2S3

FROM ur_table

GROUP BY ID

Open in new window

0
 
LVL 2

Expert Comment

by:sunil_mails
ID: 24803600
put ur table structure to help experts gv u perfect solution.. if possible put 4-5 sample rows
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now