나는 하나의 필드 (계정)를 항상 표시하고 그 다음 계수 또는 합계 기준에 대해 하위 쿼리를 표시하고자하는 테이블이 있습니다.SQL 하위 쿼리 같은 테이블의 모든 데이터
예 :
select ndhist_acct_nbr,
(select count(ndhist_acct_nbr) from dbo.nd_history where ndhist_type = '30'
and ndhist_rsn = '0' and ndhist_trcd = 'NF*' and ndhist_ref_type = '0' and ndhist_dt >= '03/01/2013') as NSF_TOTAL,
(select sum(ndhist_amt) from dbo.nd_history where ndhist_type = '30'
and ndhist_rsn = '98' and ndhist_trcd = 'TW0' and ndhist_ref_type = '11' and ndhist_dt >= '03/01/2013') as SIG_SPEND,
(select count(ndhist_acct_nbr) from dbo.nd_history where ndhist_type = '30'
and ndhist_rsn = '23' and ndhist_trcd = 'TW0' and ndhist_ref_type = '11' and ndhist_dt >= '03/01/2013') as PIN_TRANS,
(select count(ndhist_acct_nbr) from dbo.nd_history where ndhist_type = '30'
and ndhist_rsn = '21' and ndhist_trcd = 'SC*' and ndhist_ref_type = '0' and ndhist_dt >= '03/01/2013') as FOREIGN_AMT_FEE
from dbo.nd_history
group by ndhist_acct_nbr
문제는 결과입니다 - 계좌 번호가 모두 표시하지만 카운트/합이 모든 데이터를 반복 필드. 어떤 도움이 굉장 할 것입니다!
스택 오버플로에 오신 것을 환영합니다! 해당 태그 (Oracle, SQL Server, MySQL 등)를 추가하여 대상으로 삼고있는 RDBMS를 지정하십시오. 보편적으로 지원되지 않는 언어 나 제품 기능을 이용하는 대답이있을 수 있습니다. 또한 특정 RDBMS로 태그를 달아서 질문에 답하는 것이 더 적합한 사람들로부터주의를받을 수 있습니다. – Taryn