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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:17:57+00:00 2026-06-01T21:17:57+00:00

Given this data, I want to sum (tbl_basket subt), multiply by discount, add shipping

  • 0

Given this data, I want to sum (tbl_basket subt), multiply by discount, add shipping charge.

# tbl_basket  order_id  qty    price     subt
                     1    1    10.00    10.00
                     1    4     5.00    20.00
                     1    3    12.00    36.00

# tbl_coupon        id          name discount
                     1     "10% off"    10.00

# tbl_shipping      id                   cost
                     1                   4.99

# tbl_order  coupon_id   shipping_id    total  
                     1             1        ?  # I want to update total

I want to query the basket:

SELECT * FROM tbl_basket WHERE order_id = $order_id

Sum the items, i think like this?

SELECT SUM(subt) FROM tbl_basket WHERE order_id = $order_id

Query the discount

SELECT discount FROM tbl_coupon AS coupon
          INNER JOIN tbl_order AS order
               WHERE coupon.id = order.coupon_id

Q) How do I merge this query into the other one in MySQL?

Q) How do set the value after the discount (new total = total*(100-discount)/100)

I felt it would make the system more robust by summing totals from the database directly, thats why I wanted to do it this way.

Q) Is there a better way to do this?

Thanks for your 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-01T21:17:59+00:00Added an answer on June 1, 2026 at 9:17 pm

    I agree with evan – doing the calculations in PHP is much better. If nothing else, you can better see what you’re doing!

    But if you really want to see what it looks like in SQL, you can try something like this:

    SELECT ((select total price query)*(select discount query) + (select shipping query))
    

    Sure, with subqueries you might get everything into a single query statement. The more you add, though, the harder it is to debug. In PHP it’s much easier to assemble the pieces.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

given this coffeescript data = Foo: B Foos: [ A, B ] Blah: Id:
Given this example data set: ----------------------------- | item | date | val | -----------------------------
Given data like this C1<-c(3,-999.000,4,4,5) C2<-c(3,7,3,4,5) C3<-c(5,4,3,6,-999.000) DF<-data.frame(ID=c(A,B,C,D,E),C1=C1,C2=C2,C3=C3) How do I go about removing
Given a data set like this; +-----+---------------------+--------+ | id | date | result |
Given this table structure, I want to flatten out the many-to-many relationships and make
Given that I have a table contains user data, like this: userID calltime result
I have 128-bit data in q-register. I want to sum the individual 16-bit block
I have some data inside this variable and I want to know how could
I get this error TypeError at /debate/1/ get_context_data() takes exactly 2 arguments (1 given)
when I look up the syntax for .data(), it gives examples like this: $('body').data('foo',

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.