-
[mysql] if(),date(),Safe modeSQL/MySQL 2021. 7. 27. 16:27
if()
where 절 조건에 맞는 튜플이 1개 있을 경우 count(*) 가 1 이 되며 java 의 삼항연산자와 같이
count(*)=1 이면 1 아니면 0 을 반환한다.
select if(count(*)=1,1,0) from member where id='' and pw='';
date()
trans_date 라는 컬럼이 date 형이여도 date() 함수로 변환 후 연산해야 오류가 나지 않는다.
select * from point_event where member_no=1 and (date(trans_date) between 2021-08-08 and 2021-09-08)
Safe mode On/Off
update 또는 delete 할 때 where 절이 없거나 where 절에 key column 외의 비교문일 때,
쉽게말해 한번에 여러 row 를 업데이트할 때, 막아두는게 Safe mode On 이다
아래의 쿼리문으로 잠시 해당 safe node 를 풀 수 있다.
set sql_safe_updates=0
'SQL > MySQL' 카테고리의 다른 글
[mysql] grant,user,index,view (0) 2021.07.24 [mysql] join,Aliases (0) 2021.07.24 [mysql] where,비교연산자,order by (0) 2021.07.23 [mysql] DDL,DML,제약조건 (0) 2021.07.23