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

  • Home
  • SEARCH
  • 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 7943547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:18:07+00:00 2026-06-04T00:18:07+00:00

Please click here for sample tables and description. I have three tables ‘PROJECTS’, ‘PROJECTMANAGER’

  • 0

Please click here for sample tables and description.

I have three tables ‘PROJECTS’, ‘PROJECTMANAGER’ and ‘MANAGERS’ as per attached images.

I need a query which can list PROJECTS managed by “PRODUCT” type managers grouped with PROJECT STATUS.
If STATUS=2 then show as Completed Projects or else In Progress Projects.

Resulted table should look like as shown in attached image.
Desired Result: http://www.dbasupport.com/forums/attachment.php?attachmentid=588&d=1336691473

The query, I need should be generic so that it can be used in any database (MySQL/Oracle/MSSQL/DB2)

Please Help.

BTW, This is not the homework…!!!!
I used sample tables.

I have tried with case when statements but don’t know how to join and at the same time use group by.

CREATE TABLE PROJECTS 
(       
    PROJECT_ID  varchar(20), 
    PROJECT_NAME  varchar(30),
    STATUS int
);

CREATE TABLE PROJECTMANAGER
(
    PROJECT_ID  varchar(20), 
    MANAGER_ID varchar(20)
);

CREATE TABLE MANAGERS
(           
    MANAGER_ID  varchar(20), 
    MANAGER_NAME  varchar(20), 
    TYPE varchar(20)
);


INSERT INTO PROJECTS (PROJECT_ID, PROJECT_NAME, STATUS) VALUES
    ('project_001', 'Project 001', 0),
    ('project_002', 'Project 002', 1),
    ('project_003', 'Project 003', 2),
    ('project_004', 'Project 004', 0),
    ('project_005', 'Project 005', 2),
    ('project_006', 'Project 006', 0),
    ('project_007', 'Project 007', 1);


INSERT INTO PROJECTMANAGER (PROJECT_ID , MANAGER_ID) VALUES
    ('project_001', 'mgr_001'),
    ('project_002', 'mgr_001'),
    ('project_001', 'mgr_002'),
    ('project_002', 'mgr_003'),
    ('project_001', 'mgr_003'),
    ('project_005', 'mgr_001'),
    ('project_004', 'mgr_002');

INSERT INTO MANAGERS (MANAGER_ID, MANAGER_NAME, TYPE) VALUES
    ('mgr_001', 'Manager 001', 'PRODUCT'),
    ('mgr_002', 'Manager 002', 'HR'),
    ('mgr_003', 'Manager 003', 'PRODUCT'),
    ('mgr_004', 'Manager 004', 'FINANCE'),
    ('mgr_005', 'Manager 005', 'PRODUCT');



Resulted Table:

MANAGER_ID  | MANAGER _NAME | COMPLETED_PROJECTS |  IN_PROGRESS_PROJECTS |
 mgr_001    | Manager 001   |        1       |            2          |
 mgr_003    | Manager 003   |        0       |            1          |
 mgr_005    | Manager 005   |        0       |            0          |
  • 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-04T00:18:09+00:00Added an answer on June 4, 2026 at 12:18 am

    Try something like this:

    SELECT
      m.manager_id,
      m.manager_name,
      SUM(CASE WHEN p.status = 2 THEN 1 ELSE 0 END) as completed,
      SUM(CASE WHEN p.status != 2 THEN 1 ELSE 0 END) as in_progress
    FROM managers m
    LEFT JOIN projectmanager pm ON (m.manager_id = pm.manager_id)
    LEFT JOIN projects p ON (p.project_id = pm.project_id)
    WHERE m.type = 'product'
    GROUP BY m.manager_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please click here for sample tables and description. I have three tables ‘PROJECTS’, 'PROJECTMANAGER'
Please click here for sample tables and description . I have two tables ‘VEHICLE’
http://www.leandrovieira.com/projects/jquery/lightbox/ sample so i have get images in while loop here is my code
In my view i have ImageView.If i click ,it should open nextview. Please help
Please see the jsfiddle sample output: offset based on svg x:12 y:34 mouse click
Please visit this link Click on first Image. Now is showing the Modal page
please how will i position the(Click to Register now and place your orders) to
Please check out: http://gherkin.co.nz/refresh/ and click on the purple box that says 'Membership chest'
light box closing automatically with in seconds. Could you help me please $(document).ready(function(){ $('.lightbox').click(function(){
I have some JQuery where when you click on a Add to Basket button

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.