-4

I have a table in which minimum and maximum temperature is stored per order no and date. I want to pick the minimum temperature and maximum temperature for each day. This should be done using SQL script.

Mistu4u
  • 5,132
  • 15
  • 53
  • 91

2 Answers2

0

You have to use group by clause, and aggregate functions min, max as below:

select date, min(temperature), max(temperature)
from table
group by date

It will work if your date have only year, month and day (01/11/2012).

Robert
  • 25,425
  • 8
  • 67
  • 81
0

In oracle:

SELECT TO_CHAR(DATE_VAL,'DD-MM-YYYY'), MAX(temperature), 
MIN(temperature) FROM table_name group by TO_CHAR(DATE_VAL,'DD-MM-YYYY');

In MySQl:

   SELECT DATE_FORMAT(DATE_VAL, '%d-%m-%Y'), max(temperature), 
   min(temperature) from table_name group by DATE_FORMAT(DATE_VAL, '%d-%m-%Y');
Md. Kamruzzaman
  • 1,895
  • 16
  • 26