TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 07-21-2009, 08:05 PM   #1 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default mysql JOIN challange

I have spent the last week trying to create a query that returns the data from one table in the format i want it but without success. I am sure I need to JOIN a table with itself but its the COUNTing of types of row which is proving most challenging. Wonder if anyone can help or even further resolve for me. Its a challange indeed.

Essentially I want a query that will take this table:

Code:
betid 	        customer 	group 	result
34		joebloggs	1	Win
34		another		1	Lose
36		mrjones		1	Win
37		joebloggs	1	Win
38		mrJones		1	Lose
38		joebloggs	1	Lose
40		joebloggs	2	Win
and reformat it in this way counting up wins and losses GROUPing by group, customer and then win and loss counts.

Code:
group		customer	Wins	Losses
1		joebloggs	2	1
1		mrjones		1	1
1		another		0	1
2		joebloggs	1	0
Handling 0 losses is not easy as I am essentially trying to return a count of value for a row that does not exist.
captainmerton is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL join total delayedinsanity MySQL & Databases 3 07-24-2008 03:53 AM
MySQL syntax for table join on delete delayedinsanity General 5 04-03-2008 05:39 PM
MySQL Sell Up Alan @ CIT The Lounge 12 01-17-2008 05:46 PM
Mysql problem, most likely related to left join Village Idiot MySQL & Databases 6 01-04-2008 06:09 AM
Notepage like application to open large MySQL files Wildhoney General 6 12-07-2007 02:18 PM


All times are GMT. The time now is 09:52 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design