INSERT INTO temp table

Posted on 2011-03-11
Medium Priority
Last Modified: 2012-05-11
Please help,

I have table emp

ID   NAME        QUAL       OJ
1    JOHN             01          1
2    DEREK          01          2
3    SUE                02          1
4    JIM                  02          2
5    DEAN              03         1
6    SUZY              01         1
7    RUTH              02         2
I have table qual
1         01             DR
2         02             MR
3         03            VSS  

And I need to get table

   1      2      1       1  
   2      1      2       0

I need how many DR, MR, VSS are in OJ

P.S. I'm using SQL 2008
Thank you very much
Question by:hrvica5
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
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 2000 total points
ID: 35107502
select e.oj
   , sum(case when QUAL = '01' then 1 else 0 end) DR
   , sum(case when QUAL = '02' then 1 else 0 end) MR
   , sum(case when QUAL = '03' then 1 else 0 end) VSS
 from emp e
group by e.oj
order by e.oj

Author Closing Comment

ID: 35108155
thank you very much

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

764 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