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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:40:40+00:00 2026-05-27T10:40:40+00:00

I have a table with fields ID, action and value. ID is the record

  • 0

I have a table with fields ID, action and value. ID is the record name, action is the identifier of what does the value represent. The values of ID in the table are duplicated with different actions and values.

Example:

ID      action      value
3603    1           78
3603    2           2
3603    3           1
5645    1           45
etc...

Now I would like to construct a select statement that would somehow get values where ID=3603 and the formula is (if action 1 then value*10, if action 2 then value*5 and if action 3 then value*2). The result for 3603 is 792.

On top of that I need this to be joined to another table where I have the same ID value (unique) and I need to order by this sum both tables…

Is that possible or should I do some cumulative table that holds this sums for each record? Problem is this is statistics calculations so every ID will get 3 inputs of the actions for every month and every year (monthly statistics).

  • 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-27T10:40:40+00:00Added an answer on May 27, 2026 at 10:40 am
    select id,action,sum(
    CASE t.action 
      WHEN 1 then t.value * 10 
      when 2 then value*5 
      when 3 then value*2 end
    ) AS S
    
    from table_multy t join table_single s on t.id=s.id
    group by t.id
    order by ( sum(
    CASE t.action 
      WHEN 1 then t.value * 10 
      when 2 then value*5 
      when 3 then value*2 end
    ) + s.other_val )
    

    to save in a historical table use:

    insert into thistory (col1,clo2,clon) select ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table LOGIN_LOG with fields ID, PLAYER, TIMESTAMP and ACTION. ACTION
I have table with some fields that the value will be 1 0. This
I have a table T with fields id, parentid , name. i make relationship
I have a table that records a sequence of actions with a field that
I have a table with three fields, FirstName, LastName and Email. Here's some dummy
I have a table with 3 fields: ID (not unique, not primary key) timestamp
I have a table with three fields, User , City and Country , where
I have a table of 2 fields. Word and timestamp. Then i have this
I have a table with 3 fields: color, fruit, date. I can pick 1
If I have a table Orders with fields CustomerID , OrderID and OrderDate ,

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.