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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.