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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:54:14+00:00 2026-06-12T11:54:14+00:00

I have a table that essentially has: person activity-code activity-value There are multiple activity-codes

  • 0

I have a table that essentially has:

person  activity-code  activity-value

There are multiple activity-codes (about 17 of them) and activity-values per person. For exmaple:

A  1   10
A  1   12
A  2   4
B  1   5
B  2   3
B  2   8

What I want is a select statement that returns something like:

A   22 4
B   5  11

So the first column is the person. The second column is the sum of all activity-values for the activity-code 1 for that person. The third column is the sum of all activity-values for the activity-code 2 for that person. etc…

In the end I want to do this and use the OUTFILE command in there as I want to dump the totals to a file to be imported into an excel file.

It seems like there is a subquery in there somewhere but I am not advanced enough to figure that out.

Any help would be greatly appreciated. I can add detail if that is going to help.

  • 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-12T11:54:15+00:00Added an answer on June 12, 2026 at 11:54 am

    Unfortunately for you, Mysql lacks the pivot command present in other databases, which makes this sort of thing a piece of cake. You’re stuck with something like

     select
          person,
          sum(case activitycode when 1 then activityvalue else 0 end),
          sum(case activitycode when 2 then activityvalue else 0 end),
          ....
     from 
          yourtable
     group by
          person
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a schema that essentially looks like this: CREATE TABLE `data` ( `id`
I have table that I insert data with following query (from c# code): INSERT
I have a table that contains multiple dropdown menus for a list of profile
I have a table that looks like this: id value AGA 0.211 AGA 0.433
I have a table that has account numbers in (account_num) and user profiles (profile_id).
I have a table that stores data that has been entered regarding the amount
In my program I have a table that, when loaded, has jQuery add some
I have a table that has reached nearly 3 million records. While I appreciate
I have a table that has column names similar to ADDRESS, OLD_ADDRESS, CITY, OLD_CITY,
I have a table that has a bunch of fields. The fields can be

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.