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 6364 게시물 읽기
No. 6364
쿼리 질문이요
작성자
KISS
작성일
2012-04-16 12:37ⓒ
2012-04-16 14:37ⓜ
조회수
6,805

질문이 있어 글을 올립니다.

고수님들 조언 부탁드립니다.

쿼리에서 특정필드의 값(숫자)를 분할해서 표시하기

예) select 필드명 from tb : 

----------------------------------------------

필드값 : 1050 이라고 했을때 특정수(100)만큼 분할해서 표시하고, 분할하고 마지막 남는 수가 (30) 이상일때는 새로운 row 표시, 그렇지 않을때는 마지막에 표시 

결과가

1  100

2 100

....

10 100

11 50  ==> 마지막 값이 30 이하이면 10번 row에 130으로 표시되어져야 함

------------------------------------

 

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

 create table cols(

col int
);
-- 대충 값 넣어가면서 go go
insert into cols( col ) values( 1020 );
delete from cols where col = 1050;
 
declare @th1 int = 100;
declare @th2 int = 30;
with nums( num )
as
(
select 1
union all select 2
union all select 3
union all select 4
union all select 5
union all select 6
union all select 7
union all select 8
union all select 9
union all select 10
union all select 11
union all select 12
-- 넉넉히 있어야 함.
)
select @th1
from cols cross join nums where ( col / @th1 > num ) and ( col % @th1 <= @th2 )
union all
select col % @th1 + @th1 from cols where ( col % @th1 <= @th2 )
 
union all
 
select @th1
from cols cross join nums where ( col / @th1 >= num ) and ( col % @th1 > @th2 )
union all
select col % @th1 from cols where ( col % @th1 > @th2 )
 
 
drop table cols;
우욱님이 2012-04-16 16:13에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
6368쿼리 질문입니다. [2]
정인수
2012-04-21
6583
6367MSSQL 2005 데이터 형식 여쭤봅니다. [1]
정필교
2012-04-19
6946
6366DB서버 동시접속 몇명까지인가요? [1]
이성안
2012-04-19
9083
6364쿼리 질문이요 [1]
KISS
2012-04-16
6805
6362select top 3 값을 변수에 담는법 저장프로시저에서요 [2]
이용한
2012-04-13
8204
6361ms-sql row 복재 connect by level < ? 기능 여부 [1]
nightbobo
2012-04-12
7142
6360아래 추가 질문입니다. varchar(max) 관련 [1]
초보
2012-04-09
8051
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.028초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다