[DB] DB sql문 1
Q. 2023년 매출은? SELECT type, sum(total), count(*) from zpan where SUBSTR(indate,1,4)='2023' and type='매출'; 그룹화 했을 시 결과 값 : SELECT b.cname, a.type, sum(a.total) from zpan as a LEFT JOIN zcompany as b on a.cid=b.id where SUBSTR(a.indate,1,4)='2023' and a.type='매출' group by b.cname; 문자열을 자를 때는 SUBSTR 함수를 사용함. SUBSTRING, LEFT, RIGHT 함수도 문자열 자를때 사용함. 참고 사이트 https://gent.tistory.com/201
2023. 2. 17.
[DB] DB sql문 (group by, union all)
Q1. 2023년 거래처별, 구분별 합계를 보여주세요(매출,매입) (컬럼명) 거래처명, 구분, 합계 select b.cname, a.type, sum(a.total) as total FROM zpan as a LEFT JOIN zcompany as b on a.cid = b.id WHERE SUBSTR(a.indate,1,4)='2023' group by a.cid, a.type order by b.cname, a.type; Q2. 2023년 거래처별, 구분별 금액합계을 보여주세요(입금,지급) (컬럼명) 거래처명, 구분, 금액합계 select b.cname, a.type, sum(a.money) as money FROM zmoney as a LEFT JOIN zcompany as b on a.cid = ..
2023. 2. 17.