본문 바로가기
[Mysql] 같은 조건으로 gruop by 할 때 우선순위사용 가능한 union SELECT animal_type,count(*) from animal_ins where animal_type='cat' union select animal_type,count(*) from animal_ins where animal_type='dog' group by animal_type; cat이 먼저 실행되어야함 union을 사용해서 합침 SELECT ANIMAL_TYPE,COUNT(ANIMAL_TYPE) FROM ANIMAL_INS WHERE ANIMAL_TYPE = 'Cat' OR ANIMAL_TYPE = 'Dog' GROUP BY ANIMAL_TYPE ORDER BY ANIMAL_TYPE; 아니면 or를 사용해서 출력가능 2022. 7. 10.
[Mysql] DISTINCT 중복 값 제거 함수 SELECT count(distinct name) from animal_ins where name is not null; count 안에 distinct 코드를 사용하여 중복값은 체크하지 않는 걸로 설정! not null 은 =가 아님 is임 문제:https://school.programmers.co.kr/learn/courses/30/lessons/59408 2022. 7. 10.
[Mysql] 테이블 3개 join , order by, group by, sum null값 지우기, case when 테이블 3개 조인하기 left join / join SELECT * FROM 테이블1 LEFT JOIN 테이블2 ON 테이블1.필드명 = 테이블2.필드명 JOIN 테이블3 ON 테이블1.필드명 = 테이블3.필드명; 으로 테이블3개를 join할 수 있습니다. 물론 동일한 값 설정은 해줘야하고요. 테이블 info, item, paly를 합쳐보겠습니다. table info table item table play table확인해보니까 info.name 과 play.name 과 같고 item.item하고 play item이 같네요. SELECT * FROM 테이블1 LEFT JOIN 테이블2 ON 테이블1.필드명 = 테이블2.필드명 JOIN 테이블3 ON 테이블1.필드명 = 테이블3.필드명; 그렇다면..! 합쳐보.. 2022. 7. 9.
[Mysql] 데이터 join, sum 예제 -korean 테이블 -history 테이블2 [1번] 방정환님의 데이터를 name, id, tel1, email, price의 총합계, service 출력 단, 이름, 아이디,전화번호1,이메일, 총구매가격, 통신사 로 출력 select korean.name as 이름, history.id as 아이디, korean.tel1 as 전화번호1, korean.email as 이메일,sum(history.goodsprice) as 총합계,korean.service as 통신사 from korean left join history on korean.id=history.id where korean.name='방정환'; select korean.name as 이름, history.id as 아이디, korean.t.. 2022. 7. 7.
[MSSQL] 특정 단어 개수 확인 하기, null값 삭제하기 특정 단어 개수 확인하기 select count(*) from 테이블명 where 필드명 like '%' select count(*) from school1$ where spart like '%공립%' select count(*) from school1$ where sname like '%유치원%' select count(*) from school1$ where saddr like '%남구%' null값 삭제 하기 delete from school1$ where stel1 is null and stel2 is null and stel3 is null; 2022. 7. 6.