database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
ㆍMS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MS-SQL Q&A 5961 게시물 읽기
No. 5961
group by 사용...?
작성자
초보임돠
작성일
2011-10-11 17:58
조회수
5,973

select A.cusdate, A.qnt1-isnull(B.trans_ut,0) as utut, A.org_gw-isnull(B.trans_gw,0) as gwgw
 from

 (select idx,prod,case when customsdate='' then 'N' else 'Y' end cusdate, qnt1,isnull(CAST(gw AS float),0) as org_gw
 from as_pulp where unload='군산항' and customsdate <>'null') A

 left outer join

 (select  pulp_idx,sum(ut) as trans_ut ,  sum(CAST(gw AS float)) as trans_gw from as_trans group by pulp_idx) B
 on A.idx = B.pulp_idx
 

결과
---------------------------------------
cusdate     utut      gwgw
---------------------------------------
     Y           96.0      48.1920 
     N          277.0    139.054 
     N          294.0    147.639 
     Y           38.0      19.0760
     Y           400.0    200.800

cusdate를 group by 해서 utut, gwgw 각각의 합을 구하고 싶습니다

도와주세요~~~

이 글에 대한 댓글이 총 1건 있습니다.

select A.cusdate, SUM( A.qnt1-isnull(B.trans_ut,0)) as utut, SUM(A.org_gw-isnull(B.trans_gw,0)) as gwgw
 from

 (select idx,prod,case when customsdate='' then 'N' else 'Y' end cusdate, qnt1,isnull(CAST(gw AS float),0) as org_gw
 from as_pulp where unload='군산항' and customsdate <>'null') A

 left outer join

 (select  pulp_idx,sum(ut) as trans_ut ,  sum(CAST(gw AS float)) as trans_gw from as_trans group by pulp_idx) B
 on A.idx = B.pulp_idx
 

group by a.cusate

1님이 2011-10-12 13:45에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
6246쿼리 질문입니다.. 도움을 부탁드려요~~ [1]
이종웅
2011-10-24
6166
6244Sql Server 2008 백업 문의 입니다. [1]
홍길동
2011-10-19
7404
5962오라클의 v$parameter와 같은 기능 [1]
된동이
2011-10-13
6127
5961group by 사용...? [1]
초보임돠
2011-10-11
5973
5960질문 하나만 더올릴게요 ㅠㅠ
송기백
2011-10-08
6116
5959쿼리 질문입니다 고수님들 도와주세요 [2]
송기백
2011-10-07
6819
5956GROUP BY 관련 질문입니다. [1]
최명근
2011-10-04
5729
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.038초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다