Go Back   SitePoint Forums > Forum Index > Program Your Site > Databases > MySQL
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Dec 6, 2005, 09:35   #1
bhutz
SitePoint Member
 
bhutz's Avatar
 
Join Date: May 2004
Location: Bedford
Posts: 13
Display all records and totals at same time

Hi Guys,

Is it possible for me to do something like this...
I have this sort of data...
Code:
12/10/2005 16:22:00 Mr Smith Title: Mr...
12/10/2005 17:39:00 Mrs Banks Title: Mrs...
12/10/2005 18:32:00 Mrs Banks Title: Mrs...
13/10/2005 16:29:00 Mr Banks Title: Mr...
13/10/2005 16:54:00 Miss Banks Title: Miss...
14/10/2005 10:28:00 Miss Banks Title: Miss...
14/10/2005 12:15:00 Ms Banks Title: Ms...
14/10/2005 12:41:00 Mr Jones Title: Mr...
14/10/2005 17:26:00 Miss Jones Title: Miss...
15/10/2005 09:30:00 Mr Jones Title: Mr...
17/10/2005 14:31:00 Mr Smith Title: Mr...
18/10/2005 12:20:00 Mr Smith Title: Mr...
18/10/2005 16:12:00 Mr Smith Title: Mr...
18/10/2005 20:42:00 Miss Smith Title: Miss...
that I return from a database query but some why I would like to also display how many messages were sent in AM or PM.
The query to get these totals is easy enough but when I use a group not all of the records are displayed.

Would it be possible to somehow include the totals in the resultset somehow using a join or something so I end up with something like this, although the records are duplicated at least I will have a record of the count of day and night messages.
Code:
DATE		TIME		RESULT		CLIENT CHARGE	DAY	NIGHT
05/10/2005	23:06	Patch Successful	6426	3.00	2	10
10/10/2005	19:56	Patch Successful	6426	3.00	2	10
10/10/2005	20:12	Patch Successful	6426	3.00	2	10
12/10/2005	19:26	Patch Successful	6426	3.00	2	10
14/10/2005	09:30	Patch Successful	6426	3.00	2	10
14/10/2005	19:01	Patch Failed	6426	0.90	2	10
15/10/2005	19:46	Patch Successful	6426	3.00	2	10
16/10/2005	13:57	Patch Successful	6426	3.00	2	10
25/10/2005	00:29	Patch Successful	6426	3.00	2	10
31/10/2005	20:42	Patch Successful	6426	3.00	2	10
bhutz is offline   Reply With Quote
Old Dec 6, 2005, 12:45   #2
r937
SQL Consultant
silver trophybronze trophy
SitePoint Award Recipient
 
r937's Avatar
 
Join Date: Jul 2002
Location: Toronto, Canada
Posts: 31,026
two different sets of data, two different queries, probably two different threads

could you focus on one set of data please, and please show a sample of how you want the totals to be displayed together with the details
r937 is online now   Reply With Quote
Old Dec 7, 2005, 01:54   #3
bhutz
SitePoint Member
 
bhutz's Avatar
 
Join Date: May 2004
Location: Bedford
Posts: 13
Sorry I should have double checked this one...I think I messed up because I am trying to do the same thing with 2 different tables, hence the 2 different examples of data.
To explain again I have a table with messages in and I am trying to retrieve messages for a given client, like so
Code:
DATE		TIME		PHONE		RESULT		CLIENT	CHARGE
2005-10-05	23:06	0800 123 123	Patch Successful	6426	3.00
2005-10-10	19:56	0800 123 123	Patch Successful	6426	3.00
2005-10-10	20:12	0800 123 123	Patch Successful	6426	3.00
2005-10-12	19:26	0800 123 123	Patch Successful	6426	3.00
2005-10-14	09:30	0800 123 123	Patch Successful	6426	3.00
2005-10-14	19:01	0800 123 123	Patch Failed	6426	0.90
2005-10-15	19:46	0800 123 123	Patch Successful	6426	3.00
2005-10-16	13:57	0800 123 123	Patch Successful	6426	3.00
2005-10-25	00:29	0800 123 123	Patch Successful	6426	3.00
2005-10-31	20:42	0800 123 123	Patch Successful	6426	3.00
Using the following query
Code:
SELECT DISTINCT `DATE`,`TIME`,PHONE, RESULT, CLIENT, CHARGE FROM mysqlPATCHLOG WHERE CLIENT = '6426' AND MONTH(DATE) = 10 AND YEAR(DATE) = 2005 ORDER BY DATE,TIME
I also wanted to be able to determine how many of these messages were night messages and how many day so that I could end up with something like this
Code:
DATE		TIME		PHONE		RESULT		CLIENT	CHARGE DAY	NIGHT
2005-10-05	23:06	0800 123 123	Patch Successful	6426	3.00		2	10
2005-10-10	19:56	0800 123 123	Patch Successful	6426	3.00		2	10
2005-10-10	20:12	0800 123 123	Patch Successful	6426	3.00		2	10
2005-10-12	19:26	0800 123 123	Patch Successful	6426	3.00		2	10
2005-10-14	09:30	0800 123 123	Patch Successful	6426	3.00		2	10
2005-10-14	19:01	0800 123 123	Patch Failed	6426	0.90		2	10
2005-10-15	19:46	0800 123 123	Patch Successful	6426	3.00		2	10
2005-10-16	13:57	0800 123 123	Patch Successful	6426	3.00		2	10
2005-10-25	00:29	0800 123 123	Patch Successful	6426	3.00		2	10
2005-10-31	20:42	0800 123 123	Patch Successful	6426	3.00		2	10
I know the query I need to show how many messages were between a certain time to determine night and day messages but can't seem to combine the two (totals and actual rows)

I guess what I really want to know is how to be able to display all messages but at the same time determine totals. THe group by function seems to prevent me from doing this so I thought maybe a join of some sort might work?
bhutz is offline   Reply With Quote
Old Dec 7, 2005, 02:55   #4
r937
SQL Consultant
silver trophybronze trophy
SitePoint Award Recipient
 
r937's Avatar
 
Join Date: Jul 2002
Location: Toronto, Canada
Posts: 31,026
okay, i see the totals now (didn't scroll right before)

nope, you can't do them that way

what i was hoping for was that you'd want them interspersed with the details, sort of like this --
Code:
DATE       TIME  RESULT           CHARGE
2005-10-14 09:30 Patch Successful 3.00
2005-10-16 13:57 Patch Successful 3.00
DAYTIME TOTALS: 2
2005-10-14 19:01 Patch Failed     0.90
2005-10-12 19:26 Patch Successful 3.00
2005-10-15 19:46 Patch Successful 3.00
2005-10-10 19:56 Patch Successful 3.00
2005-10-10 20:12 Patch Successful 3.00
2005-10-31 20:42 Patch Successful 3.00
2005-10-05 23:06 Patch Successful 3.00
2005-10-25 00:29 Patch Successful 3.00
NIGHTTIME TOTALS: 8
even this would be difficult to do with sql

my suggestion: use application reporting software
r937 is online now   Reply With Quote
Old Dec 7, 2005, 03:05   #5
bhutz
SitePoint Member
 
bhutz's Avatar
 
Join Date: May 2004
Location: Bedford
Posts: 13
oh boo
To explain further )) I have to put the list of messages on a PDF, which has been done but there is also a totals section. So it doesn't really matter where I have the daytime and night time totals I just need the values.
Looks like I will have to just use two queries, not ideal but I have a quick look for what you suggested but can't find anything just yet.

I'll keep looking but if you had some specific reporting software in mind please can you name them. Wouldn't this software have to perform just as many queries as I would to retrieve this data anyway?
bhutz is offline   Reply With Quote
Old Dec 7, 2005, 03:09   #6
r937
SQL Consultant
silver trophybronze trophy
SitePoint Award Recipient
 
r937's Avatar
 
Join Date: Jul 2002
Location: Toronto, Canada
Posts: 31,026
i was thinking of something like Crystal Reports, but don't spend too much time looking, if you are rolling your own then just go with two queries

interspersing the totals with the details would have needed two queries too, except they would be combines in a UNION
r937 is online now   Reply With Quote
Old Dec 7, 2005, 03:13   #7
bhutz
SitePoint Member
 
bhutz's Avatar
 
Join Date: May 2004
Location: Bedford
Posts: 13
Thanks for the input...I think 2 queries shouldn't be all that slow but for future reference wanted to know if there was a better method really
bhutz is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 17:26.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved