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

  • Home
  • SEARCH
  • 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 225717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:26:27+00:00 2026-05-11T19:26:27+00:00

I would like to know if its possible to get 2 sums from one

  • 0

I would like to know if its possible to get 2 sums from one query using the table values and then add them togther.

Here is some simple table & data which might help.

    CREATE TABLE `cartcontents` (
  `id` int(11) NOT NULL auto_increment,
  `code` varchar(40) NOT NULL,
  `qty` int(10) NOT NULL,
  `price` decimal(30,2) NOT NULL,
  `cart_id` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `zone` (`zone_code`,`cart_id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records 
-- ----------------------------
INSERT INTO `cartcontents` VALUES ('5', '011242077783866125432', '1', '36.00', '2');
INSERT INTO `cartcontents` VALUES ('4', '011242077793513596890', '3', '33.00', '4');
INSERT INTO `cartcontents` VALUES ('6', '011242077649557011493', '1', '110.00', '4');
INSERT INTO `cartcontents` VALUES ('7', '011242077724922511037', '1', '177.00', '5');

So I would like to be able collect the total qty & total value for a given cart_id.

So this would mean if I had 3 in the qty filed the sum would need to be (qty * price) for each zone then add them in total for the cart_id.

So in the above example if I was looking for the values for cart_id 4 The values I would hope I could return would be qty = 4 & total value = 209

Hope this makes sense and thanks if you can 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-05-11T19:26:28+00:00Added an answer on May 11, 2026 at 7:26 pm

    Something like this should work:

    SELECT SUM(qty) AS qty, SUM(qty * price) AS total
    FROM cartcontents
    GROUP BY cart_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if its possible to get full screen snapshots from
I would like to know if its possible to get the users location without
I would like to know if its possible to write a nested select statment?
I would like to know if its possible to clear the current information stored
Hi I would like to know if its possible to do something similar to
I would like to know if its possible without having to define an extra
I would like to know if it is possible to get attributes of the
I would like to know if its possible to use python to connect to
I would like to know if it's possible to pass a parameter to a
I would like to know: If it's possible to use Lazarus (Pascal) for both

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.