cmb Posted November 29, 2011 Share Posted November 29, 2011 this is my query SELECT SUM(no_Yards) AS 'yards', AVG(no_yards) AS 'avg', MAX(no_Yards) AS 'max', MIN(no_Yards) AS 'min' FROM swimming WHERE Season = '$ws' and when i display the data i want to display the date that the max and the min happened (from the database in the column Day_Swam) something like this <?php echo "<tr>"; echo "<td style='background-color:#F90'>Max Length:</td>"; echo "<td>" . number_format($wsi_row['max']) . "</td>"; echo "<td>" . DATE WOULD GO HERE . "</td>"; echo "</tr>"; echo "</tr><tr>"; echo "<td style='background-color:#F90'>Min Length:</td>"; echo "<td style='background-color:#FF9'>" . number_format($wsi_row['min']) . "</td>"; echo "<td>" . DATE WOULD GO HERE . "</td>"; echo "</tr>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/252013-view-the-date-with-other-mysql-data/ Share on other sites More sharing options...
cmb Posted November 29, 2011 Author Share Posted November 29, 2011 i got this for my max query but idk how to get the min value select * from (select a.no_Yards as yards, a.Day_Swam as 'date', a.Season as season, (select 1 + count(*) from swimming b where b.no_Yards > a.no_Yards and Season = '5') as rank from swimming as a) as x where Season = '5' and x.rank = '1' Quote Link to comment https://forums.phpfreaks.com/topic/252013-view-the-date-with-other-mysql-data/#findComment-1292361 Share on other sites More sharing options...
cmb Posted November 29, 2011 Author Share Posted November 29, 2011 my final query SELECT * FROM (SELECT a.no_Yards AS 'yards', a.Day_Swam AS 'date', a.Season AS 'season', (SELECT sum(no_yards) FROM swimming WHERE Season = '6') AS 'totalyard', (SELECT AVG(no_Yards) FROM swimming WHERE Season = '6') AS 'avg', (SELECT count(*) FROM swimming WHERE Season ='6') AS 'timelaps', (SELECT 1 + count(*) FROM swimming b WHERE b.no_Yards > a.no_Yards AND Season = '6') AS hrank, (SELECT 1 + count(*) FROM swimming b WHERE b.no_Yards < a.no_Yards AND Season = '6') AS lrank FROM swimming AS a) AS x WHERE Season = '6' AND (hrank = '1' OR lrank = '1') Quote Link to comment https://forums.phpfreaks.com/topic/252013-view-the-date-with-other-mysql-data/#findComment-1292389 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.