[MySQL]プログラマ


きっとSQL最高になります…!
私はSQLの最高の人になってデータベースを打ちます!
SELECTは繰り返さない
SELECT DISTINCT Country FROM Customer;
SELECT COUNT(DISTINCT Country) FROM Customers;
コラム内の名前でCOUNTを区別する
SELECT ANIMAL_TYPE, COUNT(ANIMAL_TYPE)
FROM ANIMAL_INS
GROUP BY ANIMAL_TYPE
ORDER BY ANIMAL_TYPE ASC

GROUP BYに条件を追加
WHERE用
GROUP BYはHAVINGで条件を設定する必要があります.
SELECT NAME, COUNT(NAME)
FROM ANIMAL_INS
GROUP BY NAME
*HAVING COUNT(NAME) > 1*

SELECT HOUR(DATETIME) AS HOUR, COUNT(NAME) AS COUNT
FROM ANIMAL_OUTS
WHERE HOUR(DATETIME) between 9 and 19
GROUP BY HOUR(DATETIME)
ORDER BY 1
SELECT hour(datetime) as HOUR, count(datetime) as COUNT
from animal_outs
where hour(datetime) between 9 and 19
group by hour(datetime)
order by 1;
何が違うのか分からないけどだめだ.