jdubwelch Posted December 16, 2007 Share Posted December 16, 2007 here's my table: Let's say we're talking about game 1 (G1): I want to get three things in one query: 1. The total number of picks made >> [ SELECT COUNT(G1) AS total FROM `picks` ] will get me that Can i combine that with: 2. The total number of times team 1 was picked ( the 1's in the G1 column) >> I can use "SELECT COUNT(G1) AS AwayTeamTotal FROM `picks` WHERE G1 = 1" 3. The total number of times team 2 was picked ( the 2's in the G1 column) >> I can use "SELECT COUNT(G1) AS HomeTeamTotal FROM `picks` WHERE G1 = 2" Is there a way to get all those queries into one, just so i don't have to go to it three times? Quote Link to comment Share on other sites More sharing options...
Barand Posted December 17, 2007 Share Posted December 17, 2007 $sql = "SELECT COUNT(G1) as total, SUM(IF(G1=1,1,0)) as hometot, SUM(IF(G1=2,1,0)) as awaytot FROM picks"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.