목록sql연습문제 (3)
영국 척척석사 유학생 일기장👩🏻🎓

1. 문제1) total_amt_usd 판매액이 가장 많은 각 region에서 sales_rep의 name을 제공하십시오.sales_rep과 관련된 total_amt_usd 총계, region 나타내기SELECT s.name rep_name, r.name region_name, SUM(o.total_amt_usd) total_amtFROM sales_reps sJOIN accounts aON a.sales_rep_id = s.idJOIN orders oON o.account_id = a.idJOIN region rON r.id = s.region_idGROUP BY 1,2ORDER BY 3 DESC; 각 region에 대한 total_amt_usd 가져오기SELECT region_name, MAX(tot..

1) NULLNULL은 0과 다릅니다, 데이터가 존재하지 않는 셀입니다.WHERE 절에서 NULL을 식별할 때 IS NULL 또는 IS NOT NULL 을 씁니다. (NULL은 SQL에서 값으로 간주되지 않기 때문에 =를 사용하지 않습니다)NULL은 LEFT 또는 RIGHT JOIN을 수행할 때 자주 발생합니다. LEFT JOIN의 왼쪽 테이블에 있는 일부 행이 오른쪽 테이블의 행과 일치하지 않으면 해당 행은 결과에 일부 NULL값을 포함합니다.NULL은 단순히 데이터베이스의 데이터가 누락된 경우에도 발생합니다.SELECT *FROM accountsWHERE primary_poc IS NOT NULL; 2) COUNTCOUNT는 NULL 값이 있는 행을 고려하지 않습니다.누락된 데이터가 있는 행을 빠르게..

1) JOIN : 한 번에 둘 이상의 테이블에서 데이터를 가져올 수 있도록 함JOIN 문을 추가하면 ON 문도 추가됨SELECT orders.*, accounts.* #테이블 이름은 항상 마침표 앞/ 열은 항상 마침표 뒤FROM ordersJOIN accountsON orders.account_id = accounts_id;SELECT orders.standard_qty, orders.gloss_qty, orders.poster_qty, accounts.website, accounts.primary_pocFROM ordersJOIN accountsON orders.account_id = accounts.id;SELECT *FROM web_eventsJOIN accountsON web_events.acco..