PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > with a simple SQL query
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
with a simple SQL query

Réponse
 
LinkBack Outils de la discussion
Vieux 15/10/2007, 17h50   #1
Water Cooler v2
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut with a simple SQL query

I have a table called my_expenses that has the following fields:


id int AUTO_INCREMENT PRIMARY KEY,
date date not null,
item varchar(255) not null,
amount decimal (4, 2) not null

I need to know the total amount of daily expenses I incur each day
with a grand total of the totals column. So, I want my output as such:

----------------------------------
date total
----------------------------------
2007-10-12 20.00
2007-10-13 0.00
2007-10-14 3.62
2007-10-15 6.48
------------------------------------
Grand total 30.10
------------------------------------

I've been able to get the sum for each day but I don't know how to get
the grand total. Here's what I've got so far:

select date, sum(amount) as TOTAL from my_expenses group by date;

That gives me something like this:

----------------------------------
date total
----------------------------------
2007-10-12 20.00
2007-10-13 0.00
2007-10-14 3.62
2007-10-15 6.48


Now I want the grand total as well. Please .

  Réponse avec citation
Vieux 15/10/2007, 18h02   #2
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with a simple SQL query

On 15 Oct, 16:50, Water Cooler v2 <wtr_...@yahoo.com> wrote:
> I have a table called my_expenses that has the following fields:
>
> id int AUTO_INCREMENT PRIMARY KEY,
> date date not null,
> item varchar(255) not null,
> amount decimal (4, 2) not null
>
> I need to know the total amount of daily expenses I incur each day
> with a grand total of the totals column. So, I want my output as such:
>
> ----------------------------------
> date total
> ----------------------------------
> 2007-10-12 20.00
> 2007-10-13 0.00
> 2007-10-14 3.62
> 2007-10-15 6.48
> ------------------------------------
> Grand total 30.10
> ------------------------------------
>
> I've been able to get the sum for each day but I don't know how to get
> the grand total. Here's what I've got so far:
>
> select date, sum(amount) as TOTAL from my_expenses group by date;
>
> That gives me something like this:
>
> ----------------------------------
> date total
> ----------------------------------
> 2007-10-12 20.00
> 2007-10-13 0.00
> 2007-10-14 3.62
> 2007-10-15 6.48
>
> Now I want the grand total as well. Please .


This sort of thing is supplied by a query management facility, not by
the query itself.

You need to surround the query with some other application, or write
it yourself.

  Réponse avec citation
Vieux 15/10/2007, 18h24   #3
Water Cooler v2
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with a simple SQL query

On Oct 15, 5:02 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 15 Oct, 16:50, Water Cooler v2 <wtr_...@yahoo.com> wrote:
>
>
>
>
>
> > I have a table called my_expenses that has the following fields:

>
> > id int AUTO_INCREMENT PRIMARY KEY,
> > date date not null,
> > item varchar(255) not null,
> > amount decimal (4, 2) not null

>
> > I need to know the total amount of daily expenses I incur each day
> > with a grand total of the totals column. So, I want my output as such:

>
> > ----------------------------------
> > date total
> > ----------------------------------
> > 2007-10-12 20.00
> > 2007-10-13 0.00
> > 2007-10-14 3.62
> > 2007-10-15 6.48
> > ------------------------------------
> > Grand total 30.10
> > ------------------------------------

>
> > I've been able to get the sum for each day but I don't know how to get
> > the grand total. Here's what I've got so far:

>
> > select date, sum(amount) as TOTAL from my_expenses group by date;

>
> > That gives me something like this:

>
> > ----------------------------------
> > date total
> > ----------------------------------
> > 2007-10-12 20.00
> > 2007-10-13 0.00
> > 2007-10-14 3.62
> > 2007-10-15 6.48

>
> > Now I want the grand total as well. Please .

>
> This sort of thing is supplied by a query management facility, not by
> the query itself.
>
> You need to surround the query with some other application, or write
> it yourself.- Hide quoted text -
>
> - Show quoted text -




Thanks. So, that is not possible with an SQL query?

  Réponse avec citation
Vieux 15/10/2007, 20h15   #4
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with a simple SQL query

Water Cooler v2 wrote:
> On Oct 15, 5:02 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>> On 15 Oct, 16:50, Water Cooler v2 <wtr_...@yahoo.com> wrote:
>>
>>
>>
>>
>>
>>> I have a table called my_expenses that has the following fields:

>>
>>> id int AUTO_INCREMENT PRIMARY KEY,
>>> date date not null,
>>> item varchar(255) not null,
>>> amount decimal (4, 2) not null

>>
>>> I need to know the total amount of daily expenses I incur each day
>>> with a grand total of the totals column. So, I want my output as
>>> such:

>>
>>> ----------------------------------
>>> date total
>>> ----------------------------------
>>> 2007-10-12 20.00
>>> 2007-10-13 0.00
>>> 2007-10-14 3.62
>>> 2007-10-15 6.48
>>> ------------------------------------
>>> Grand total 30.10
>>> ------------------------------------

>>
>>> I've been able to get the sum for each day but I don't know how to
>>> get the grand total. Here's what I've got so far:

>>
>>> select date, sum(amount) as TOTAL from my_expenses group by date;

>>
>>> That gives me something like this:

>>
>>> ----------------------------------
>>> date total
>>> ----------------------------------
>>> 2007-10-12 20.00
>>> 2007-10-13 0.00
>>> 2007-10-14 3.62
>>> 2007-10-15 6.48

>>
>>> Now I want the grand total as well. Please .

>>
>> This sort of thing is supplied by a query management facility, not by
>> the query itself.
>>
>> You need to surround the query with some other application, or write
>> it yourself.- Hide quoted text -
>>
>> - Show quoted text -

>
>
>
> Thanks. So, that is not possible with an SQL query?


It would be possible to craft one using a UNION, but it really wouldn't be
worth it!


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h46.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11834 seconds with 12 queries