2024/05 3

sql 문제풀이 조각 모음 [MYSQL]

1. !=  사용 시 null은 포함되지 않는다.-- [!=2] : 2를 제외한 숫자만 출력select name from Customer where referee_id != 2-- [!=2 and is null] : 2가 아닌 수 + null 출력select name from Customer where referee_id != 2 or referee_id is null 2. null이 아닌 값을 찾을 땐 is not null 을 사용한다. ( != null (x)) 3. coalesce() : 해당 컬럼값이 null일 시 대체할 값을 설정한다. coalesce(컬럼명, 대체값)select Prices.product_id, coalesce(round(sum(price*units)/sum(units),2),..

ALGORITHM 2024.05.22

leetcode 1517 Find Users With Valid E-Mails [MYSQL]

리뷰공부한 것RLIKE, REGEX 함수 - 문자열 패턴을 정규표현식을 사용해서 비교하고 일치 여부를 확인한다.-- regular like, regular expressionRLIKE '^[조건 범위]'REGEX '^[조건 범위]'  정규표현식  a-zA-Z : 알파벳0-9 : 숫자^ : 문자열 시작 표시[] : 범위 설정+ : 조건 잇기$ : 문자열 종료 설정. 설정하지 않으면 뒤에 문자열이 추가될 수 있다.* : 직전의 조건 범위를 충족하는 문자의 개수는 0 이상이다.\\. : 메타문자인 도트 앞에 이스케이프 문자(역슬래시) 두개 붙이기 문제더보기더보기Table: Users+---------------+---------+| Column Name | Type |+---------------+-..

ALGORITHM 2024.05.20

leetcode 1731 The Number of Employees Which Report to Each Employee [MYSQL]

리뷰셀프조인이 생각 안 나서 오래 고민했다. "the number of employees who report directly to them  by managers" 이 부분이 문제였는데, count(reports_to)로 적으니 group by에 적용돼서 0 출력. 서브쿼리를 사용해서  count(employee_id)를 출력하려고 하니까 이경우엔 group by에 적용시킬 수가 없었다. 공부한 것the average age of the reports rounded to the nearest integer. 반올림-- CEILING (x)round(avg(table2.age)) 문제더보기1731. The Number of Employees Which Report to Each Employee Solved..

ALGORITHM 2024.05.10