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 1051 게시물 읽기
No. 1051
[질문]mssql case 문의 중첩
작성자
이진수
작성일
2003-11-20 14:30
조회수
8,627

안녕하세요?

case( case( case(case( ....

이런 방식으로 조건을 걸어서 쿼리를 하여 100... 이상 할려면 어떻게 해야 합니까?

도와 주세요...

 

참고 문서나 방법등을 알고 싶습니다.

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

case 을 여러개 쓰시겠다는건지 아니면 case문 하나에 case를 여러개 쓰시겠다는 건지 질문의 의도를 정확히 모르겠네요

case문을 이용해서 여러개의 값을 한줄로 나오게 한다면 이런식으로 하면 될겁니다. 이게 답변이 될런지 모르겟네요 수고

select  a.line_code, c.nacf_name, a.name chulhaju_name, d.item itempum,             
d.name itempum_name, a.item, b.name item_name,       
sum(case  when  a.unit_count < 10   then (a.quantity)                                        
else 0                                                                                      
end) as qty10,                                                                               
sum(case  when unit_count >= 10  and a.unit_count <= 15   then (a.quantity)                  
else 0                                                                                      
end) as qty15,                                                                               
sum(case  when unit_count >= 16  and a.unit_count <= 20   then (a.quantity)                  
else 0                                                                                      
end) as qty20,                                                                               
sum(case  when unit_count >= 21  and a.unit_count <= 25   then (a.quantity)                  
else 0                                                                                      
end) as qty22,                                                                               
sum(case  when unit_count >= 26  and a.unit_count <= 30   then (a.quantity)                  
else 0                                                                                      
end) as qty30,                                                                               
sum(case  when unit_count >= 31    then (a.quantity)                                         
else 0                                                                                      
end) as qty40,                                                                               

 

sum(case  when  a.unit_count < 10   then (a.amt)                                             
else 0                                                                                      
end) as amt10,                                                                               
sum(case  when unit_count >= 10  and a.unit_count <= 15   then (a.amt)                       
else 0                                                                                      
end) as amt15,                                                                               
sum(case  when unit_count >= 16  and a.unit_count <= 20   then (a.amt)                       
else 0                                                                                      
end) as amt20,                                                                               
sum(case  when unit_count >= 21  and a.unit_count <= 25   then (a.amt)                       
else 0                                                                                      
end) as amt22,                                                                               
sum(case  when unit_count >= 26  and a.unit_count <= 30   then (a.amt)                       
else 0                                                                                      
end) as amt30,                                                                               
sum(case  when unit_count >= 31    then (a.amt)                                              
else 0                                                                                      
end) as amt40                                                                                
from sales a,goods b, customer c, goods d                                                   
where  a.item = b.item                                                                      
and  substring(b.item,1,2) + '00' = d.item                                                  
and a.line_code = c.code                                                                    
and  a.weight = 15                                                                          
   and  a.sale_date between '2003-09-01'                                        
   and                '2003-09-31'
and a.item = 1030
group by  a.line_code, a.name,c.nacf_name,  d.item, d.name,  a.item, b.name
order by a.line_code                                                                        


 

 

대사모님이 2003-11-24 16:49에 작성한 댓글입니다.
이 댓글은 2003-11-24 16:52에 마지막으로 수정되었습니다. Edit

먼저 답변 감사합니다..

제가 요구하는건 중첩을 예기합니다.

case(case ...then... else ...)...then .... else...

이런식으로 10단계이상의 깊이로 들어가서 검색을 가능하게 하고 싶습니다.

 

이진수님이 2003-11-29 15:06에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
1055오류 질문 [2]
김근영
2003-11-22
64718
1054update할 때
GIX
2003-11-21
4383
1053mssql에서 사용하던 게시판을 mysql로 바꾸었는데, 좀 가르쳐주세요. [1]
김철희
2003-11-20
5332
1051[질문]mssql case 문의 중첩 [2]
이진수
2003-11-20
8627
1050쿼리문을 잘 모르겠어요.. [2]
조태욱
2003-11-18
4979
1048프로시져에서 [1]
돈세자
2003-11-18
6276
1047장장 프로시져에서 테이블 선택하는 방법 [1]
백종규
2003-11-17
4468
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.029초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다