일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- git commit merge
- 전략패턴
- react
- cypress React
- 가상면접2장
- 가상면접3장
- 리팩터링2판테스트
- 시스템설계
- Git commit 합치기
- gitsquash
- 시스템설계방법
- 시스템설계면접예시
- awss3
- 시스템설계면접팁
- 테스트코드책
- 가상면접으로대규모시스템
- react-ga
- formik react-query submitting not working
- 리액트구글애널리틱스
- git squash
- file not found Error
- formik submitting not working
- 리팩토링2판4장
- 디자인패턴
- s3이미지다운로드됨
- FirebaseAnalytics
- cypressBDD
- git commit 협업
- 시스템설계면접
- 헤드퍼스트전략패턴
- Today
- Total
mingg IT
[pegjs] node-sql-parser 예제 본문
1. npm install node-sql-parser
const opt = {
database: "MySQL", // MySQL is the default database
};
const { Parser } = require("node-sql-parser/build/mysql");
const parser = new Parser();
const ast = parser.astify("SELECT * FROM t", opt);
const sql = parser.sqlify(ast, opt);
console.log(JSON.stringify(ast, null, 2));
console.log(sql); // SELECT * FROM `t`
1. Selector
const ast = parser.astify("SELECT empno as ENO FROM emp", opt);
SELECT `empno` AS `ENO` FROM `emp`
1-2). 한글 alias
const ast = parser.astify("SELECT empno as 번호 FROM emp", opt);
2. 서브쿼리 UPDATE 문 SET 절
UPDATE TEAM A SET A.E_TEAM_NAME = (SELECT X.STADIUM_NAME FROM STADIUM X WHERE X.STADIUM_ID = A.STADIUM_ID)
3.) 서브쿼리 INSERT 문의 VALUES 절
4. FULL OUTER JOIN
select * from dept FULL OUTER join dept_team on dept.deptno = dept_team.deptno
5. self join은 inner join으로 해야 됨
select worker.empno, worker.ename, manager.ename from emp worker inner join emp manager on(worker.mgr = manager.empno)
6. UNION
SELECT DEPTNO FROM EMP UNION SELECT DEPTNO FROM DEPT
7. UNION ALL
8. ROLLUP
SELECT DNAME, JOB, MGR, SUM(SAL) FROM EMP, DEPT WHERE DEPT.DEPTNO = EMP.DEPTNO GROUP BY ROLLUP(DNAME, (JOB, MGR))
8-1. 간단한 ROLLUP 예제
SELECT ENAME, DEPTNO FROM EMP GROUP BY ROLLUP(ENAME, DEPTNO)
9. CUBE
SELECT DNAME, JOB, MGR, SUM(SAL) FROM EMP, DEPT WHERE DEPT.DEPTNO = EMP.DEPTNO GROUP BY CUBE(DNAME, (JOB, MGR))
9-1. 간단한 CUBE 예제
SELECT ENAME, DEPTNO FROM EMP GROUP BY CUBE(ENAME, DEPTNO)
안되는 것
1. INTERSECT, MINUS
2. 계층형 질의
'SQL' 카테고리의 다른 글
[SQL] 제 39회 SQLD 시험 합격 후기 (1) | 2021.01.02 |
---|---|
[javaScript] 오픈소스 js-sql-parser 예제 (0) | 2020.12.31 |