Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8059665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:44:42+00:00 2026-06-05T09:44:42+00:00

ANSWER : Here’s the final query built from @Michael ‘s answer: SELECT Emp_ID, MAX(CASE

  • 0

ANSWER: Here’s the final query built from @Michael ‘s answer:

SELECT 
    Emp_ID,
    MAX(CASE WHEN Skill_ID = 'WLN' THEN (Rating > 0) END) AS `WLN`,
    MAX(CASE WHEN Skill_ID = 'LOC' THEN (Rating > 0) END) AS `LOC`,
    MAX(CASE WHEN Skill_ID = 'BRV' THEN (Rating > 0) END) AS `BRV`,
    AVG(CASE WHEN Skill_ID IN ('KWH','SIC','DOL') THEN (Rating) END) > 0 AS `KSD`
FROM Emp_Skill
WHERE Emp_ID IN (120,348,361,370)
GROUP BY Emp_ID

QUESTION:

I have the following Emp_Skill table:

Skill_ID*  Emp_ID*  Rating
--------------------------
     WLN      120        6
     WLN      348        5
     WLN      361        7
     WLN      370        8
     LOC      120        7
     LOC      370        7
     LOC      348        7
     BRV      120        3
     LOC      361        6
     BRV      348        1
     KWH      348        5
     KWH      120        5
     KWH      361        5
     KWH      370        5
     SIC      361        8
     SIC      348        4
     SIC      120        2
     DOL      348        5
     DOL      361        8

and I need to know if an arbitrary number of employees have a positive skill rating for each skill.

So let’s say I want to look at this info for employees 120, 348, 361 and 370.

Query 1 for skill WLN is:

SELECT `Emp_ID`, `Rating` > 0 AS `WLN` FROM `Emp_Skill` WHERE `Skill_ID` = 'WLN' AND `Emp_ID` IN (120,348,361,370)

which returns:

Emp_ID   WLN
------------
   120     1
   348     1
   361     1
   370     1

Query 2 for skill LOC is:

SELECT `Emp_ID`, `Rating` > 0 AS `LOC` FROM `Emp_Skill` WHERE `Skill_ID` = 'LOC' AND `Emp_ID` IN (120,348,361,370)

which returns:

Emp_ID   LOC
------------
   120     1
   348     1
   361     1
   370     1

Query 3 for skill BRV is:

SELECT `Emp_ID`, `Rating` > 0 AS `BRV` FROM `Emp_Skill` WHERE `Skill_ID` = 'BRV' AND `Emp_ID` IN (120,348,361,370)

which returns:

Emp_ID   BRV
------------
   120     1
   348     1

and Query 4 for skill KSD is:

SELECT `Emp_ID`, AVG(`Rating`) > 0 AS `KSD` FROM `Emp_Skill` WHERE `Skill_ID` IN ('KWH','SIC','DOL') AND `Emp_ID` IN (120,348,361,370) GROUP BY `Emp_ID`

which returns:

Emp_ID   KSD
------------
   120     1
   348     1
   361     1
   370     1

Question is: How do I efficiently combine these queries into one result table and have them all in one go, i.e.:

Emp_ID   WLN   LOC   BRV   KSD
------------------------------
   120     1     1     1     1
   348     1     1     1     1
   361     1     1  NULL?    1
   370     1     1  NULL?    1

possibly from a combined SELECT statement? (the NULL value could be anything that evaluates to FALSE in the returned result set)

OR: performance-wise, will it be better if I just query each skill rating one by one (using the 4 queries above)?

Sorry if this is elementary for some peeps out there, but I’ve pulled a lot of hair out and I still haven’t killed this. lol. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:44:44+00:00Added an answer on June 5, 2026 at 9:44 am

    This is done with a pivot query, which amounts to a bunch of CASE statements. I think this should get you close to what you need:

    SELECT 
      Emp_ID,
      MAX(CASE WHEN Skill_ID = 'WLN' THEN  (Rating > 0) END) AS `WLN`,
      MAX(CASE WHEN Skill_ID = 'LOC' THEN  (Rating > 0) END) AS `LOC`,
      MAX(CASE WHEN Skill_ID = 'BRV' THEN  (Rating > 0) END) AS `BRV`,
      AVG(CASE WHEN Skill_ID IN ('KWH','SIC','DOL') THEN  (Rating > 0) END) AS `KSD`
    FROM Emp_Skill
    GROUP BY Emp_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed the answer from here but it didn't work for me: Is possible
This snippet is from an earlier answer here on SO. It is about a
Taken from this answer here : static const qi::rule<std::string::iterator, ast_t()> node = '{' >>
I tried the steps from the answer here: Hibernate Validator, custom ResourceBundleLocator and Spring
I'm using the method from the accepted answer here to construct a gameloop thread.
I've read the disappointing answer here regarding enabling logging of WCF messages from code,
I have an OrderedHash, generated from the answer here that looks like this: <OrderedHash
I copied the code from the answer here and I still am getting a
Following on from the best answer here: How much overhead does SSL impose? Is
I have reference the answer here Select whole word with getSelection . I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.