mydb=# SELECT * FROM weather; city | temp_low | temp_high | prcp | date ---------------+----------+-----------+------+------------ San Francisco | 46 | 50 | 0.25 | 1994-11-27 San Francisco | 43 | 57 | 0 | 1994-11-29 Hayward | 37 | 54 | | 1994-11-29 a | 45 | 50 | 0.25 | 1996-12-22
mydb=# SELECT city, temp_low, temp_high, prcp, dateFROM weather; city | temp_low | temp_high | prcp | date ---------------+----------+-----------+------+------------ San Francisco | 46 | 50 | 0.25 | 1994-11-27 San Francisco | 43 | 57 | 0 | 1994-11-29 Hayward | 37 | 54 | | 1994-11-29 a | 45 | 50 | 0.25 | 1996-12-22 (4rows)
mydb=# SELECT city, (temp_high+temp_low)/2AS temp_avg, dateFROM weather; city | temp_avg | date ---------------+----------+------------ San Francisco | 48 | 1994-11-27 San Francisco | 50 | 1994-11-29 Hayward | 45 | 1994-11-29 a | 47 | 1996-12-22
mydb=# SELECT * FROM weather mydb-# WHERE city = 'San Francisco'AND prcp > 0.0; city | temp_low | temp_high | prcp | date ---------------+----------+-----------+------+------------ San Francisco | 46 | 50 | 0.25 | 1994-11-27 (1row)
mydb=# SELECT * FROM weather mydb-# ORDERBY city; city | temp_low | temp_high | prcp | date ---------------+----------+-----------+------+------------ Hayward | 37 | 54 | | 1994-11-29 San Francisco | 46 | 50 | 0.25 | 1994-11-27 San Francisco | 43 | 57 | 0 | 1994-11-29 a | 45 | 50 | 0.25 | 1996-12-22
mydb=# SELECT * FROM weather ORDERBY city DESC; city | temp_low | temp_high | prcp | date ---------------+----------+-----------+------+------------ a | 45 | 50 | 0.25 | 1996-12-22 San Francisco | 46 | 50 | 0.25 | 1994-11-27 San Francisco | 43 | 57 | 0 | 1994-11-29 Hayward | 37 | 54 | | 1994-11-29 (4rows)