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 5935097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:12:21+00:00 2026-05-22T15:12:21+00:00

I have three tables: user(id, name); tasks(id, user_id, text, date); bonus(id, user_id, sum, date,

  • 0

I have three tables:

user(id, name);

tasks(id, user_id, text, date);

bonus(id, user_id, sum, date, type).

I’m trying to write a query that will give me a list of all users, quantity of their tasks and a sum of bonuses of every type, each in separate column.

There are three types of bonuses:

type = (1, 2, 3)

So, I mean a table, which looks like this

name | task_count | bonus_1 | bonus_2 | bonus_3
  • 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-05-22T15:12:22+00:00Added an answer on May 22, 2026 at 3:12 pm
    SELECT u.name, 
            t.task_count, 
            SUM(CASE WHEN b.type=1 then b.sum END) AS bonus_1,
            SUM(CASE WHEN b.type=2 then b.sum END) AS bonus_2,
            SUM(CASE WHEN b.type=3 then b.sum END) AS bonus_3
    FROM user u 
    LEFT JOIN (SELECT user_id, COUNT(*) AS task_count 
               FROM tasks 
               GROUP BY user_id) t ON t.user_id = u.id
    LEFT JOIN bonus b ON b.user_id = u.id 
    GROUP BY u.id,u.name,t.task_count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables: USER: user_id (pk); username FIELD: field_id (pk); name METADATA: metadata_id
I have three tables to define users: USER: user_id (int), username (varchar) USER_METADATA_FIELD: user_metadata_field_id
I have three tables: User: UserId (pk) FirstName Lastname Messages: MessageId (pk) Heading Body
I have a database with three tables: user_table country_table city_table I want to write
I have say three tables. Projects Id Name Categories Id Name ProjectCategories Id ProjectId
I have three tables [USER] --Master user table [KEYWORD] --Master keyword table [USER_KEYWORD] --[USER]-[KEYWORD]
I have table with data about tasks like Id, Name, Date, WorkerId, VehicleId (and
Let's say I have three tables: table1 fields: memberid | name table2 fields: interestId
Ok here is the question I have three tables events - id - name
Suppose I have three tables: user , group and xref , a table that

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.