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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:33:59+00:00 2026-06-11T01:33:59+00:00

I am trying to create a mysql select query of which calculates a value

  • 0

I am trying to create a mysql select query of which calculates a value based on two other fields.

This is my query,

SELECT request_id, (
unit_cost * quantity
) AS claim_value
FROM  `xx_non_part_usage` 
WHERE request_id = request_id
GROUP BY request_id

The query above only brings back the total_value for one of the rows.

For example – here is some sample data,

ID      REQUEST_ID      QUANTITY        UNIT_VALUE
1       10001           2.0             3.00
2       10001           1.0             19.00
3       10003           0.5             18.00
4       10001           10.0            12.00
5       10003           0.75            6.76
6       10002           9.0             3.20
7       10001           0.10            13.80
8       10001           1.0             90.99
9       10004           6.75            3.00
10      10009           3.23            87.00 

As you can see there are several rows of REQUEST_ID ‘10001’. What the query needs to do is REQUEST_ID * QUANTITY then group them so it only returns the final value price (adding all of the results from the multiply sum (REQUEST_ID * QUANTITY).

Here is an expected result of what I am hoping to get (different example on REQUEST_ID 10003,

REQUEST_ID      TOTAL_VALUE
10003           14.07
10004           20.75
...
...

Thank you in advance.

  • 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-11T01:34:01+00:00Added an answer on June 11, 2026 at 1:34 am

    Why do you use “where” clause?

    mysql> select * from test;
    +------------+------------+----------+
    | request_id | unit_value | quantity |
    +------------+------------+----------+
    |          1 |          3 |        2 |
    |          1 |         19 |        1 |
    |          2 |       6.76 |     0.75 |
    |          2 |         18 |      0.5 |
    +------------+------------+----------+
    4 rows in set (0.00 sec)
    
    mysql> SELECT request_id, sum(unit_value * quantity) as x from test group by request_id;
    +------------+--------------------+
    | request_id | x                  |
    +------------+--------------------+
    |          1 |                 25 |
    |          2 | 14.070000171661377 |
    +------------+--------------------+
    2 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a mysql table from the inner join between two other
Im trying to create a function, that will return a mysql query, which i
I am trying to use PHP and MySQL's Create Table Select between two different
I trying to create a MySql Query from the $_POST values trouble is i
I am trying to create this table in a MySQL database CREATE TABLE IF
I am trying to create a name,value pair in Hibernate which gets returned as
I'm trying to create a drop down select option using PHP, MySQL, and ajadx
I have a MySQL query like this: SELECT cp.plan_name, cp.plan_time FROM courses c INNER
Im trying to create relationships between four tables in MySql: mainnodes (ID) subnodes (ID)
I am trying to create a table in MySql using php. My code looks

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.