Jump to content

view the date with other mysql data


cmb

Recommended Posts

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>";
?>

 

Link to comment
https://forums.phpfreaks.com/topic/252013-view-the-date-with-other-mysql-data/
Share on other sites

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'

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')

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.