SQL

DataBase/JOOQ

[JOOQ] SQL pretty.

https://www.jooq.org/doc/3.2/manual/sql-building/queryparts/pretty-printing/ Pretty printing SQL As mentioned in the previous chapter about SQL rendering, there are some elements in the org.jooq.RenderContext that are used for formatting / pretty-printing rendered SQL. In order to obtain pretty-printed SQL, just use the following custom settings: www.jooq.org Spring의 webConfig 클래스에 아래와 같이 Bean을 ..

DataBase/SQL

한 컬럼에 대해서 두 개 이상의 조건을 적용하는 쿼리

테이블을 조회하다보면 한 컬럼에 두개 이상의 조건을 걸어야 할 때가 있습니다. 예를 들면 아래와 같습니다. ex) 구매일이 '2021-04-01' 이전과 이후 데이터를 모두 가지고 있는 회원 데이터를 조회 하려면? SELECT * FROM member_order m1 INNER JOIN member_order m2 ON m1.id = m2.id AND m1.buy_date > '2021-04-01' AND m2.buy_date

DataBase/My-Batis

[MyBatis/MySQL] Result Map을 조심 하세요.

- 문제 상황이 발생했다. 어떤 데이터를 조회하는데 일부가 누락되어 조회되는 상황발생. - 어떤 select 쿼리에 아래와 같이 limit 100이 적용 되 있다. pageable이 null 일 경우 조회결과에 limit 100을 건다. limit가 없을 시 해당쿼리의 실행결과가 122건이라고 할 때, limit가 적용되 있으면 몇건을 반환할까? limit 100 이니까 당연히 100건인것 같지만, 현실은 24건을 반환한다. 원인은 result Map 이 적용되 있기 때문. resultMap이란 결과값을 map에다 담아주는 역할을 함. resultMap을 찾아가보자. 해당 resultMap의 안에서 collection 작업을 통해서 grouping 해주기 떄문에 100개의 row가 24개로 결과가 나오게..

DataBase/My-Batis

[MyBatis/MySQL] 쿼리 작성시 Tip 모음

- 일반적인 SQL문과 마찬가지로 컬럼명 대소문자 상관없이 값을 조회, 수정 가능.

DataBase/SQL

[MySQL/SQL] update 시 테이블 조인. update table join.

update시 관련 테이블의 데이터를 이용하려면 아래와 같이 조인 하여 사용한다. update account a inner join account_order o on a.id = o.user_id set a.order_expiry_at = o.order_end_at WHERE o.current_status = 'ORDERFAILED' AND o.updated_at >= '2020-10-21' AND o.error_msg = 'no value present';

PCOSPD 100LRE SCRIE4A2
'SQL' 태그의 글 목록