Data Science/DB+SQL
[MYSQL] 3개 컬럼을 내림차순으로 3개의 컬럼으로 재배치하는 SQL
-- 테이블 생성 CREATE TEMPORARY TABLE t ( id1INT ,id2INT ,id3INT ,valint ) ; -- 테스트 데이터 입력 INSERT INTO t SELECT 1 AS id1, 2 as id2, 3 AS id3, 1 AS val UNION ALL SELECT 2 AS id1, 1 as id2, 3 AS id3, 1 AS val UNION ALL SELECT 3 AS id1, 2 as id2, 1 AS id3, 1 AS val UNION ALL SELECT 2 AS id1, 3 as id2, 1 AS id3, 1 AS val ; -- id1,id2,id3 값을 큰 값부터 max_id, mid_id, min_id로 재배치 한다. SELECT GREATEST(id1, id2, ..
2021. 9. 14. 18:51
최근댓글