Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

detail and grouping

 
   Database Help (Home) -> mySQL RSS
Next:  update Oracle from 10.2.0.2.0 to 10.2.0.2.0  
Author Message
bill

External


Since: May 09, 2010
Posts: 2



(Msg. 1) Posted: Sun May 09, 2010 3:30 am
Post subject: detail and grouping
Archived from groups: comp>databases>mysql (more info?)

I would like to select and list all the transactions within date
limits, _and_ print the totals grouped by provider. If I use the
group by clause, all I get is one transaction amount and the total,
both are correct but not what I want.
eg:
provider date amount total
bill 2010-05-01 10
bill 2010-05-02 20
bill 30

george 2010-05-02 10
george 2010=05-05 10
george 20

I don't know if this is possible.

 >> Stay informed about: detail and grouping 
Back to top
Login to vote
Captain Paralytic

External


Since: Jan 14, 2008
Posts: 245



(Msg. 2) Posted: Sun May 09, 2010 6:31 am
Post subject: Re: detail and grouping [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On May 9, 11:30 am, bill wrote:
> I would like to select and list all the transactions within date
> limits, _and_ print the totals grouped by provider.  If I use the
> group by clause, all I get is one transaction amount and the total,
> both are correct but not what I want.
> eg:
> provider   date           amount  total
> bill           2010-05-01      10
> bill           2010-05-02      20
> bill                                         30
>
> george 2010-05-02        10
> george 2010=05-05       10
> george                                   20
>
> I don't know if this is possible.

You were nearly there with your subject. If you had put
detail and total
and searched this group, you would have dome across:
http://groups.google.com/group/comp.databases.mysql/browse_frm/thread/...50f3901

The last post in that thread from me will point you to the MySQL GROUP
BY Modifier of ROLLUP, which is just what you are after.

 >> Stay informed about: detail and grouping 
Back to top
Login to vote
J.O. Aho

External


Since: Dec 01, 2003
Posts: 190



(Msg. 3) Posted: Sun May 09, 2010 8:25 am
Post subject: Re: detail and grouping [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> I would like to select and list all the transactions within date
> limits, _and_ print the totals grouped by provider. If I use the
> group by clause, all I get is one transaction amount and the total,
> both are correct but not what I want.
> eg:
> provider date amount total
> bill 2010-05-01 10
> bill 2010-05-02 20
> bill 30
>
> george 2010-05-02 10
> george 2010=05-05 10
> george 20
>
> I don't know if this is possible.


Not sure what you mean.

If you want to group and get totals, then use SUM(coulmname)

SELECT provider, date, SUM(amount) AS amount, total FROM ... GROUP BY provider


If you want to get all the rows for a provider, then use ORDER BY,

SELECT provider, date, amount, total FROM ... ORDER BY provider


If you want to have both, then you would need to use nested SELECT with an UNION.

Or you can make it simple and do the summing up in the script/progeaming
language you are using to connect to the mysql.

--

//Aho
 >> Stay informed about: detail and grouping 
Back to top
Login to vote
Captain Paralytic

External


Since: Jan 14, 2008
Posts: 245



(Msg. 4) Posted: Sun May 09, 2010 10:11 am
Post subject: Re: detail and grouping [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On May 9, 3:55 pm, The Natural Philosopher
wrote:
> J.O. Aho wrote:
> >> I would like to select and list all the transactions within date
> >> limits, _and_ print the totals grouped by provider.  If I use the
> >> group by clause, all I get is one transaction amount and the total,
> >> both are correct but not what I want.
> >> eg:
> >> provider   date           amount  total
> >> bill           2010-05-01      10
> >> bill           2010-05-02      20
> >> bill                                         30
>
> >> george 2010-05-02        10
> >> george 2010=05-05       10
> >> george                                   20
>
> >> I don't know if this is possible.
>
> > Not sure what you mean.
>
> > If you want to group and get totals, then use SUM(coulmname)
>
> > SELECT provider, date, SUM(amount) AS amount, total FROM ... GROUP BY provider
>
> > If you want to get all the rows for a provider, then use ORDER BY,
>
> > SELECT provider, date, amount, total FROM ... ORDER BY provider
>
> > If you want to have both, then you would need to use nested SELECT with an UNION.
>
> > Or you can make it simple and do the summing up in the script/progeaming
> > language you are using to connect to the mysql.
>
> the latter is usually easier.
>
> Its nice to have SQL do all the work, but in reality an SQL query is a
> single result set from the data: what you need is two results.
>
> Either two separate enquires, or build the second result from an
> iteration through the first result.

Or "in reality" use the solution that I posted!!!

SELECT
provider,
date,
SUM(amount)
FROM test.transactions t
GROUP BY provider, date WITH ROLLUP

Gives:
provider date SUM(amount)
bill 2010-05-01 10
bill 2010-05-02 20
bill 30
george 2010-05-02 10
george 2010-05-05 10
george 20
50
 >> Stay informed about: detail and grouping 
Back to top
Login to vote
The Natural Philosopher

External


Since: Oct 01, 2009
Posts: 27



(Msg. 5) Posted: Sun May 09, 2010 11:25 am
Post subject: Re: detail and grouping [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

J.O. Aho wrote:
>> I would like to select and list all the transactions within date
>> limits, _and_ print the totals grouped by provider. If I use the
>> group by clause, all I get is one transaction amount and the total,
>> both are correct but not what I want.
>> eg:
>> provider date amount total
>> bill 2010-05-01 10
>> bill 2010-05-02 20
>> bill 30
>>
>> george 2010-05-02 10
>> george 2010=05-05 10
>> george 20
>>
>> I don't know if this is possible.
>
>
> Not sure what you mean.
>
> If you want to group and get totals, then use SUM(coulmname)
>
> SELECT provider, date, SUM(amount) AS amount, total FROM ... GROUP BY provider
>
>
> If you want to get all the rows for a provider, then use ORDER BY,
>
> SELECT provider, date, amount, total FROM ... ORDER BY provider
>
>
> If you want to have both, then you would need to use nested SELECT with an UNION.
>
> Or you can make it simple and do the summing up in the script/progeaming
> language you are using to connect to the mysql.
>
the latter is usually easier.

Its nice to have SQL do all the work, but in reality an SQL query is a
single result set from the data: what you need is two results.

Either two separate enquires, or build the second result from an
iteration through the first result.
 >> Stay informed about: detail and grouping 
Back to top
Login to vote
The Natural Philosopher

External


Since: Oct 01, 2009
Posts: 27



(Msg. 6) Posted: Sun May 09, 2010 1:25 pm
Post subject: Re: detail and grouping [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Captain Paralytic wrote:
> On May 9, 3:55 pm, The Natural Philosopher
> wrote:
>> J.O. Aho wrote:
>>>> I would like to select and list all the transactions within date
>>>> limits, _and_ print the totals grouped by provider. If I use the
>>>> group by clause, all I get is one transaction amount and the total,
>>>> both are correct but not what I want.
>>>> eg:
>>>> provider date amount total
>>>> bill 2010-05-01 10
>>>> bill 2010-05-02 20
>>>> bill 30
>>>> george 2010-05-02 10
>>>> george 2010=05-05 10
>>>> george 20
>>>> I don't know if this is possible.
>>> Not sure what you mean.
>>> If you want to group and get totals, then use SUM(coulmname)
>>> SELECT provider, date, SUM(amount) AS amount, total FROM ... GROUP BY provider
>>> If you want to get all the rows for a provider, then use ORDER BY,
>>> SELECT provider, date, amount, total FROM ... ORDER BY provider
>>> If you want to have both, then you would need to use nested SELECT with an UNION.
>>> Or you can make it simple and do the summing up in the script/progeaming
>>> language you are using to connect to the mysql.
>> the latter is usually easier.
>>
>> Its nice to have SQL do all the work, but in reality an SQL query is a
>> single result set from the data: what you need is two results.
>>
>> Either two separate enquires, or build the second result from an
>> iteration through the first result.
>
> Or "in reality" use the solution that I posted!!!
>
> SELECT
> provider,
> date,
> SUM(amount)
> FROM test.transactions t
> GROUP BY provider, date WITH ROLLUP
>
> Gives:
> provider date SUM(amount)
> bill 2010-05-01 10
> bill 2010-05-02 20
> bill 30
> george 2010-05-02 10
> george 2010-05-05 10
> george 20
> 50


wasn't aware of ROLLUP. Will have to look that up..
 >> Stay informed about: detail and grouping 
Back to top
Login to vote
bill

External


Since: May 09, 2010
Posts: 2



(Msg. 7) Posted: Mon May 10, 2010 3:47 am
Post subject: Re: detail and grouping [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On May 9, 9:31 am, Captain Paralytic wrote:
> On May 9, 11:30 am, bill wrote:
>
> > I would like to select and list all the transactions within date
> > limits, _and_ print the totals grouped by provider.  If I use the
> > group by clause, all I get is one transaction amount and the total,
> > both are correct but not what I want.
> > eg:
> > provider   date           amount  total
> > bill           2010-05-01      10
> > bill           2010-05-02      20
> > bill                                         30
>
> > george 2010-05-02        10
> > george 2010=05-05       10
> > george                                   20
>
> > I don't know if this is possible.
>
> You were nearly there with your subject. If you had put
> detail and total
> and searched this group, you would have dome across:http://groups.google.com/group/comp.databases.mysql/browse_frm/thread...
>
> The last post in that thread from me will point you to the MySQL GROUP
> BY Modifier of ROLLUP, which is just what you are after.

lovely - thanks
I know I can do it in PHP, but this was an attempt to learn more
MySQL, which both I and NP did.
 >> Stay informed about: detail and grouping 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Best way to issue hundreds of inserts/updates??? - Using mysql 4.0.23- What is the best way to execute several (hundreds of) inserts and updates? Rather than issuing tons of individual inserts and updates, can I send the strings to a text file and then have mysql do them all?? IE : query.txt insert..

MySQL freezes, brings XP machine to a grinding halt - I've been using MySQL for a while for fairly light database development on my XP machine. Currently, I am just starting a new project and have experienced some big problems with MySQL today both on my office machine and at home where running a particular...

login as user 'root' but do not have root privlages and my.. - Hi gang: I'm experiencing a problem with MySQL -- I updated MySQL from version 4.1.0 to 4.1.10 and now when I login as root it doesn't show all the databases I should have access to, nor it doesn't recognize me being logged in as root (via..

FLUSH TABLES hangs if table is locked - Using FLUSH TABLES via the C query API mysql_query() hangs if the table is locked already. That is to say, nothing prevents me from running a LOCK TABLES twice; it won't tell me "it's already locked, don't try to run a FLUSH". Anyone know ...

Tool to convert DDL in graphical diagram? - Does anyone know of a tool that will create a graphical diagram from a DDL (SQL create script)? Preferable a free open-source tool. Thanks, A
   Database Help (Home) -> mySQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]