473,408 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Total without and with a condition

How do I get the total without a condition and the total with the
condition at the same time?

This is my mysql table:

id datetimeconfirmed customerid amount
1 2007-08-14 06:19:03 1 12.25
2 2007-08-06 06:19:19 1 15
3 2007-08-02 06:19:41 2 5
4 2007-08-07 06:19:58 2 7.25
5 2007-08-09 06:36:41 3 25

If I run this query:

select customerid, sum(amount) from test
group by customerid

I get this result:

customerid sum( amount )
1 27.25
2 12.25
3 25

If I run this query:

select customerid, sum(amount) from test
where datetimeconfirmed < '2007-08-08'
group by customerid

I get this result:

customerid sum( amount )
1 15
2 12.25

Which query do I have to run to get this result?

customerid sum( amount ) total
1 15 27.25
2 12.25 12.25
3 NULL 25

Regards,

Jan Nordgreen

PS: I posted this question at comp.databases.mysql a week ago, but no
answers. I know this is a php question, but still.

Aug 18 '07 #1
1 1534
damezumari wrote:
How do I get the total without a condition and the total with the
condition at the same time?

This is my mysql table:

id datetimeconfirmed customerid amount
1 2007-08-14 06:19:03 1 12.25
2 2007-08-06 06:19:19 1 15
3 2007-08-02 06:19:41 2 5
4 2007-08-07 06:19:58 2 7.25
5 2007-08-09 06:36:41 3 25

If I run this query:

select customerid, sum(amount) from test
group by customerid

I get this result:

customerid sum( amount )
1 27.25
2 12.25
3 25

If I run this query:

select customerid, sum(amount) from test
where datetimeconfirmed < '2007-08-08'
group by customerid

I get this result:

customerid sum( amount )
1 15
2 12.25

Which query do I have to run to get this result?

customerid sum( amount ) total
1 15 27.25
2 12.25 12.25
3 NULL 25

Regards,

Jan Nordgreen

PS: I posted this question at comp.databases.mysql a week ago, but no
answers. I know this is a php question, but still.
Answered over on comp.databases.mysql
Aug 18 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Graham | last post by:
I have a variable which can be in the format "mm:ss" or "hh:mm:ss". I would like to extract the total number of seconds from this. Ie "01:30" would be 90 seconds. Thanks in advance !
4
by: James Greig | last post by:
hello people, i'm just learning javascript, could someone point me in the direction of an example of the following, or give me some clues as to how it might be done: what i would like to do...
7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
4
by: mukeshhtrivedi | last post by:
I have TYPE field which has 3 data like HEAD, TRACK and PANEL. Now whenever any person works on HEAD we put 8 Hrs in HRS filed and in LABOR field it reflects the dollar value automatically like...
2
by: Jana | last post by:
Using Access 97. Background: I have a main report called rptTrustHeader with a subreport rptTrustDetails in the Details section of the main report. The main report is grouped by MasterClientID. ...
22
by: John | last post by:
Hi Folks, I'm experimenting a little with creating a custom CEdit control so that I can decide on what the user is allowed to type into the control. I started off only allowing floating point...
5
by: solargovind | last post by:
Hi, I hve some problem in query. My query is too long and linked with many table which make you confusion. So, hereby i explain you my problem by below example. The tables and Fields are.. ...
17
by: Umesh | last post by:
Please try to do it while I try myself!
21
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.