sledge4
11-04-2009, 12:24 AM
Hi,
I'm having some trouble with a query. Maybe someone could shed some light?
I have a table with the following data..
ID | iFin | iOwner
1 | 1 | Tom
2 | 3 | Dave
3 | 1 | Tom
4 | 5 | Will
5 | 3 | Dave
Trying to the get the data to output as...
iOwner| Races | Win | Place | Third | Fourth | Fifth
Tom | 2 | 2 | 0 | 0 | 0 | 0
Dave | 2 | 0 | 0 | 2 | 0 | 0
Will | 1 | 0 | 0 | 0 | 0 | 1
Essentially i'm counting how many 1's a name has and also how many total times the name appears.
So in the case of Tom, his name occurs 2 times and he has two 1's and 0 of any other number.
Dave's name shows twice, and has two 3's.
Hope this makes sense.
Any questions let me know.
Thanks in advance!
Will
PS - Here's a copy of the query I have now. All it does correctly is count the number of times each iOwner appears. Everything else just outputs 0's.
SELECT DISTINCT '', iOWNER, COUNT(iOWNER) AS Races,
(SELECT COUNT(iFIN) FROM racestats
WHERE iOWNER = '' AND iFIN = '1') win,
(SELECT COUNT(iFIN) FROM racestats
WHERE iOWNER = '' AND iFIN = '2') place,
(SELECT COUNT(iFIN) FROM racestats
WHERE iOWNER = '' AND iFIN = '3') third,
(SELECT COUNT(iFIN) FROM racestats
WHERE iOWNER = '' AND iFIN = '4') fourth,
(SELECT COUNT(iFIN) FROM racestats
WHERE iOWNER = '' AND iFIN = '5') fifth
FROM racestats
GROUP BY iOWNER, win, place, third, fourth, fifth
ORDER BY Races DESC
I'm having some trouble with a query. Maybe someone could shed some light?
I have a table with the following data..
ID | iFin | iOwner
1 | 1 | Tom
2 | 3 | Dave
3 | 1 | Tom
4 | 5 | Will
5 | 3 | Dave
Trying to the get the data to output as...
iOwner| Races | Win | Place | Third | Fourth | Fifth
Tom | 2 | 2 | 0 | 0 | 0 | 0
Dave | 2 | 0 | 0 | 2 | 0 | 0
Will | 1 | 0 | 0 | 0 | 0 | 1
Essentially i'm counting how many 1's a name has and also how many total times the name appears.
So in the case of Tom, his name occurs 2 times and he has two 1's and 0 of any other number.
Dave's name shows twice, and has two 3's.
Hope this makes sense.
Any questions let me know.
Thanks in advance!
Will
PS - Here's a copy of the query I have now. All it does correctly is count the number of times each iOwner appears. Everything else just outputs 0's.
SELECT DISTINCT '', iOWNER, COUNT(iOWNER) AS Races,
(SELECT COUNT(iFIN) FROM racestats
WHERE iOWNER = '' AND iFIN = '1') win,
(SELECT COUNT(iFIN) FROM racestats
WHERE iOWNER = '' AND iFIN = '2') place,
(SELECT COUNT(iFIN) FROM racestats
WHERE iOWNER = '' AND iFIN = '3') third,
(SELECT COUNT(iFIN) FROM racestats
WHERE iOWNER = '' AND iFIN = '4') fourth,
(SELECT COUNT(iFIN) FROM racestats
WHERE iOWNER = '' AND iFIN = '5') fifth
FROM racestats
GROUP BY iOWNER, win, place, third, fourth, fifth
ORDER BY Races DESC