[プログラマー]-レベル2 MySQL
質問する
リンク
に答える
1.猫と犬が何匹いるか
リンク
に答える
1.猫と犬が何匹いるか
SELECT ANIMAL_TYPE, COUNT(ANIMAL_TYPE) AS count
FROM ANIMAL_INS
GROUP BY ANIMAL_TYPE
ORDER BY ANIMAL_TYPE;
2.ルーシーとエラを探すSELECT ANIMAL_ID, NAME, SEX_UPON_INTAKE
FROM ANIMAL_INS
WHERE NAME
IN ('Lucy', 'Ella', 'Pickle', 'Rogan', 'Sabrina', 'Mitty')
ORDER BY ANIMAL_ID;
3.最高価格を求めるSELECT MIN(DATETIME) FROM ANIMAL_INS;
4.同名動物を探すSELECT NAME, COUNT(NAME) AS COUNT
FROM ANIMAL_INS
GROUP BY NAME
HAVING COUNT(NAME) > 1
ORDER BY NAME;
5.elという名前の動物を探すSELECT ANIMAL_ID, NAME
FROM ANIMAL_INS
WHERE NAME LIKE '%el%' AND ANIMAL_TYPE = 'Dog'
ORDER BY NAME;
6.動物の数を得るSELECT COUNT(ANIMAL_ID) AS count FROM ANIMAL_INS;
7.養子縁組を探す(1)SELECT date_format(DATETIME, '%k') AS HOUR, COUNT(date_format(DATETIME, '%k')) AS COUNT
FROM ANIMAL_OUTS
GROUP BY HOUR
HAVING(HOUR > 8) AND (HOUR < 20)
ORDER BY HOUR * 1;
8.処理NULLSELECT ANIMAL_TYPE, IFNULL(NAME, 'No name') AS NAME, SEX_UPON_INTAKE
FROM ANIMAL_INS
ORDER BY ANIMAL_ID;
9.中性化の有無を知るSELECT ANIMAL_ID, NAME,
CASE
WHEN SEX_UPON_INTAKE LIKE 'Neutered%' THEN 'O'
WHEN SEX_UPON_INTAKE LIKE 'Spayed%' THEN 'O'
ELSE 'X'
END AS '중성화'
FROM ANIMAL_INS
ORDER BY ANIMAL_ID;
10.重複除外SELECT COUNT(DISTINCT NAME) AS count FROM ANIMAL_INS;
11.DATETIMEからDATEへの変換SELECT ANIMAL_ID, NAME, date_format(DATETIME, '%Y-%m-%d') AS '날짜'
FROM ANIMAL_INS
ORDER BY ANIMAL_ID;
Reference
この問題について([プログラマー]-レベル2 MySQL), 我々は、より多くの情報をここで見つけました https://velog.io/@0_0/프로그래머스-Level2-MySQLテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol