루시와 엘라 찾기 동물 보호소에 들어온 동물 중 이름이 Lucy, Ella, Pickle, Rogan, Sabrina, Mitty인 동물의 아이디와 이름, 성별 및 중성화 여부를 조회하는 SQL 문을 작성
동물 중 이름이 Lucy, Ella, Pickle, Rogan, Sabrina, Mitty : IN
SELECT animal_id, name, sex_upon_intake
from animal_ins
WHERE NAME IN ('Lucy', 'Ella', 'Pickle', 'Rogan', 'Sabrina', 'Mitty')
ORDERBY ANIMAL_ID;
Restaurant Growth 당신은 식당 주인이고 가능한 확장을 분석(매일 적어도 한 명의 고객이 있을 것입니다). 7일 기간(즉, 오늘 + 6일 전) 동안 고객이 지불한 금액의 이동 평균을 계산 average_amount는 소수점 이하 두자리로 반올림 Visited_on을 기준으로 오름차순으로 정렬된 결과 테이블을 반환
지불한 금액의 이동 평균 : SUM(amount) /7
소수점 이하 두자리로 반올림 : Round
SELECT visited_on, (SELECTSUM(amount) FROM customer WHERE visited_on BETWEEN DATE_SUB(c.visited_on, INTERVAL6DAY) AND c.visited_on) AS amount,
ROUND((SELECTSUM(amount) /7FROM customer WHERE visited_on BETWEEN DATE_SUB(c.visited_on, INTERVAL6DAY) AND c.visited_on), 2) AS average_amount
FROM customer c
WHERE visited_on >= (SELECT DATE_ADD(MIN(visited_on), INTERVAL6DAY) FROM customer)
GROUPBY visited_on;
Population Census Given the CITY and COUNTRY tables, query the sum of the populations of all cities where the CONTINENT is 'Asia'
the sum of the populations : sum
the CONTINENT is 'Asia' : where
selectsum(c.population)
from city c
join country y on y.code = c.countrycode
where y.continent ='Asia';