[プログラマー]-1級MySQL


質問する
リンク
に答える
1.すべてのレコードを表示
SELECT * FROM ANIMAL_INS;
2.最大値を取得
SELECT MAX(DATETIME) FROM ANIMAL_INS;
3.無名動物のID
SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NULL;
4.逆順序ソート
SELECT NAME, DATETIME FROM ANIMAL_INS ORDER BY ANIMAL_ID DESC;
5.名前のついた動物のID
SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NOT NULL;
6.病気の動物を探す
SELECT ANIMAL_ID, NAME FROM ANIMAL_INS WHERE INTAKE_CONDITION IN ('Sick');
7.小動物を探す
SELECT ANIMAL_ID, NAME FROM ANIMAL_INS WHERE INTAKE_CONDITION NOT IN ('Aged');
8.動物のIDと名前
SELECT ANIMAL_ID, NAME FROM ANIMAL_INS ORDER BY ANIMAL_ID;
9.複数の条件でソート
SELECT ANIMAL_ID, NAME, DATETIME FROM ANIMAL_INS ORDER BY NAME ASC, DATETIME DESC;
10.上位n名レコード
SELECT NAME FROM ANIMAL_INS ORDER BY DATETIME ASC LIMIT 1;