Created
May 31, 2012 11:45
-
-
Save gennad/2842869 to your computer and use it in GitHub Desktop.
Задача на SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Задача: есть таблица | |
| fish | |
| name CHAR(20) | |
| price INT(5) | |
| date DATE | |
| --В таблице есть данные: | |
| forel 2012-01-01 10 | |
| forel 2012-01-03 6 | |
| treska 4 2012-01-02 | |
| treska 1 2012-01-08 | |
| --Нужно узнать стоимость рыбы в последний день. | |
| --Решение | |
| SELECT F.name, F.date, F.price FROM fish F JOIN ( | |
| SELECT MAX(date) max_date, name FROM fish GROUP BY name) AS J | |
| ON J.max_date = F.date AND J.name = F.name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment