안녕하세요 정렬문의드립니다! 0 11 1,565

by 지메이비 MSSQL [2022.05.20 17:52:42]


select case 1 when grouping(a.dealerCode) then ''총계'' when grouping(b.largeCode) then ''소계'' 
else DBO.UF_BASE_BigSellerCode(a.dealerCode,a.storeCode,a.sellerCode,b.largeCode)end BigSellerCode, 

' ' ' ' ' ' '

group by rollup( (DBO.UF_BASE_BigSellerCode(a.dealerCode,a.storeCode,a.sellerCode,b.largeCode),a.dealerCode), (a.storeCode,a.sellerCode,b . . . .. .  ))

order by case when DBO.UF_BASE_BigSellerCode(a.dealerCode,a.storeCode,a.sellerCode,b.largeCode) is null then 1 else 0 end desc, DBO.UF_BASE_BigSellerCode(a.dealerCode,a.storeCode,a.sellerCode,b.largeCode) desc , . . . . .

bigsellercode storename modifierdate stockinday
A0173789 a3호)호연숙(보건대본관) 20170228 20170302
A0173789 a3호)호연숙(보건대본관) 20170228 20170302
소계 NULL NULL NULL
A0173361 9호)경기여성능력개발센터 20220520 20170302
A0173361 9호)경기여성능력개발센터 20220520 20170302
소계 NULL NULL NULL
미지정입니다. 2호)세원화성 20170228 20170302

총계               NULL                           NULL           NULL

이 결과를 desc로 만들었는데요.. 이상태에서 또 

A0173361 , 9호)경기여성능력개발센터 를 맨위로 가게 할순 없나요? 다시 오름차순으로 영어로 시작하는것들만 한에서는 오름차순으로 하고싶어요

 

 

 

by 우리집아찌 [2022.05.20 18:09:33]

DBO.UF_BASE_BigSellerCode <= 어떤역활의 함수일까요?


by 지메이비 [2022.05.21 12:33:18]

bigsellercode를 나타내는 함수입니다


by 마농 [2022.05.23 08:28:12]

원하는 순서가 맞는지 모르겠네요?
영어는 오름차순 나머지는 내림차순?
혹시 호수로 정렬하고자 하는 것 아닍가요?
만약. 9호) 와 10호) 를 내림차순 정렬하면 10호가 먼저 나올까요? 아닙니다.
맨 첫자리 9 보다 1 이 먼저이므로 10호) 가 먼저 나옵니다.
a3호) 와 a4호) 는 뭐가 먼저 나와야 하나요?
오름차순이 맞는지 내림차순이 맞는지?
호수로 정렬하고자 하는게 맞는지? 아닌지?
명칭이 항상 "??호)" 형태로 시작하는지?
영문은 a 외에 다른 것도 있는지? 항상 한자리인지?


by 지메이비 [2022.05.23 09:18:40]

읽어보니 질문이 이상하네요

BigSellerCode 순으로 asc를 걸고싶은데 

asc를 걸면 총계랑 미지정입니다 가 맨위에 나오더라구요 

제가 원하는건 A0173361라는 bigsellercode가 결과값중에 제일 작은 코드인데 총계가밑으로가고 

A0173361 9호)경기여성능력개발센터 가 제일 앞으로 왔으면 좋겠습니다

 


by 마농 [2022.05.23 09:50:27]

모호한 표현, 두리뭉실한 표현 말고, 정확한고 구체적인 표현 부탁드립니다.
코드순 인가요?
"미지정입니다." 도 코드로 나오는 건가요?
소게나 총계등의 위치는 어떻게 되나요?


by 지메이비 [2022.05.23 09:52:54]

소계 총계는 bigsellerCode 기준으로 내고있습니다

bigsellerCode순으로 정렬입니다

미지정입니다도 bigsellercode 에 나타나는 결과값입니다


by 마농 [2022.05.23 09:58:39]

소계나 총계는 그대로 아래쪽에 위치하면 되는지?


by 마농 [2022.05.23 09:57:44]

결과에 표시되고 있는 modifierdate 나 stockinday 는 어느테이블의 컬럼인가요?
정확한 정렬을 하려면 전체 컬럼들의 정보가 필요합니다.
쿼리가 생략되어 있어 알 수가 없네요.


by 지메이비 [2022.05.23 10:01:56]
select  case 1 when grouping(a.dealerCode) then ''총계'' when grouping(b.largeCode) then ''소계'' '
else DBO.UF_BASE_BigSellerCode(a.dealerCode,a.storeCode,a.sellerCode,b.largeCode)end BigSellerCode, 
		if(@A_dealerCode='1050')
		begin
		set @qry=@qry+char(13)+' 		isnull(DBO.UF_STORENAME(a.dealerCode,a.storeCode),''오산물류센터'') storeName,				
		end
		else
		begin
		DBO.UF_STORENAME(a.dealerCode,a.storeCode) storeName,										
		end
                convert(varchar,a.modifierdate,112)  modifierdate,											
		stockinday,	'
		case grouping(a.dealerCode) when 0 then
	       (case when a.orders_restrictcount is null then isnull(b.restrictCount,'''') else a.orders_restrictcount end)end  as restrictCount,																			
		isNull(b.sellerMaterialCode,'''') as sellerMaterialCode,									
		b.materialName,																				
		b.dimension,																				
		sum((a.materialqty-a.rtnqty)) as RealQty,														
		DBO.UF_UNITNAME(b.unitcode) as unitName,													
		a.remark,																					
	        a.modifierdate,																				
		b.isuse,																					
		DBO.UF_DealerInfoName(a.dealerCode,a.storeCode) as DealerInfoName,							
		a.storeCode, '
		a.sellingPrice, '
		sum(a.sellingAmt) sellingAmt, '
		sum(a.sellingVat) sellingVat, '
		a.sellerCode, '
		DBO.UF_SELLERNAME(a.dealercode,a.sellerCode) as sellerName, '
		a.dealerCode, '
		(select isnull(anotherclientcode,'''') from client where dealercode='''+@A_dealerCode+''' and clientcode=a.sellercode ) anothersellercode	'
		from orders a,material b	'
		where a.dealercode   = '''+@A_dealerCode+''''
		and a.stockinday between '''+@A_startDay+''' and '''+@A_endDay+''''
		and a.dealercode   =  b.dealerCode '
		and a.materialCode =  b.materialCode'

전체쿼리는 이렇습니다!

소계총계는 넵 그대로 아래쪽에 위치하면 됩니다!

modifierdate ,  stockinday 둘다 orders 테이블입니다.


by 마농 [2022.05.23 13:10:41]
SELECT ...
  FROM ...
 WHERE ...
 GROUP BY ROLLUP (...)
 ORDER BY GROUPING(a.dealerCode), a.dealerCode, 
        , GROUPING(a.storeCode)
        , CASE WHEN BigSellerCode = '미지정입니다.' THEN 'ZZZ' ELSE BigSellerCode END
        , GROUPING(a.modifierdate), a.modifierdate
;

 


by 지메이비 [2022.05.23 14:51:35]

마농님 감사합니다!

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입