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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:36:59+00:00 2026-05-31T01:36:59+00:00

I have the following table : group_id amount type 1 10 1 1 2

  • 0

I have the following table :

group_id    amount  type
1           10      1
1           2       1
1           5       2
1           4       3
2           5       1

and I am looking for a view that will aggregate the data in this table such that the view produces something like this and can hopefully do it in a dynamic way:

group_id    type1_amount    type2_amount    type3_amount
1           12              5               4
2           1               NULL            NULL

My preference is to use a view in MySQL (if you have a better option I am open to hear it) and the big restriction of views in MySQL is that sub selects in the FROM clause are not allowed.

  • 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-31T01:37:01+00:00Added an answer on May 31, 2026 at 1:37 am
    SELECT
        group_id,
        SUM(CASE WHEN type = 1 THEN amount END) AS type1_amount,
        SUM(CASE WHEN type = 2 THEN amount END) AS type2_amount,
        SUM(CASE WHEN type = 3 THEN amount END) AS type3_amount
    FROM your_table
    GROUP BY group_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table with data: t1 (results): card_id group_id project_id user_id The
I have the following tables: Table: user_groups (many-to-many) user_id (int) group_id (varchar) Table: profile_groups
So, I have got following data in a MySQL table: mysql> SELECT * FROM
I have the following table structure in my db (MySQL): id group_id item_id project_id
I have the following query, and it produces a table. SELECT c.name AS campaign
I have a table with purchased orders data. Each row contails the amount of
I have the following query: select column_name, count(column_name) from table group by column_name having
I have the following example in a SQL table Cust Group Sales A 1
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
I have a the following table with rows: =============================================== id| name | group1 |

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.