473,788 Members | 2,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 datetimeconfirm ed 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 datetimeconfirm ed < '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 1554
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 datetimeconfirm ed 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 datetimeconfirm ed < '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
2833
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
11827
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 is make a self totalling version of this page > http://www.ayrshirehousing.org.uk/applications/applications.html so that basically as a person checked or unchecked boxes, a
7
12092
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 to know this number after the first FETCH, isn't it? On a side note, why queries using LIMIT are SO terribly slow, compared to cursors and sometimes even ones without LIMIT? Shouldn't LIMIT be internally implemented using cursor mechanism then?...
4
1431
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 $160 (8*20=160).Now I want to display the total of Head, Track and Panel in following; Actual Cost for Head: (All head total should display here if I have more than one head work) Actual Cost for Track:(All head total should display here if I...
2
2330
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. There are also several other subreports in the main report's footer. The rptTrustDetails subreport has two grouping levels MasterClientID and ClientID, with headers and footers for each grouping level. In the ClientID footer, I have an...
22
3178
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 numbers then added support for putting in lat/lon coordinates. I tried this little piece of code inside the OnChar function but compiler complained about missing ';' after "case _T('W'):"
5
2497
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.. student tbl --------- stud_id stud_name
17
12185
by: Umesh | last post by:
Please try to do it while I try myself!
21
17457
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), but each answer is given a different point value for each question. For instance, question 1 might ask "Do you like candy?" and if you answer Yes you will get +1, No will earn you -1, and Don't know will net you zero points. The next question might...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10118
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6750
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.