입출금기록 10개의 데이터를 newid()함수를 통해 랜덤으로 가져온다고 했을때
입금비율6,출금비율4 이런식으로 데이터를 가져오는 방법이 있을까요?
select top 6 * from 입출금 where 결과='완료' and 금액 between 100000 and 20000000 and type='입금'
union
select top 4 * from 입출금 where 결과='완료' and 금액 between 100000 and 20000000 and type='출금
order by NEWID()
이렇게 하니까 UNION, INTERSECT 또는 EXCEPT 연산자가 포함된 경우에는 ORDER BY 항목이 SELECT 목록에 나타나야 합니다.
이런 메세지가 뜨네요
어떻게 해야 할까요
mssql 2008입니다
Comment 5
-
짱나부러
2015.09.10 17:33
-
minsouk
2015.09.10 17:48
한번 더 싸서 쓰세요 -
렌슈유
2015.09.10 17:50
(select top 6 * from 입출금 where 결과='완료' and 금액 between 100000 and 20000000 and type='입금')
union
(select top 4 * from 입출금 where 결과='완료' and 금액 between 100000 and 20000000 and type='출금)
order by NEWID()이렇게 하라는 말씀이신가요? 그래도 안되네요..
-
짱나부러
2015.09.10 17:53
select top 6 * from 입출금 where 결과='완료' and 금액 between 100000 and 20000000 and type='입금'
unionselect *
from(select top 4 * from 입출금 where 결과='완료' and 금액 between 100000 and 20000000 and type='출금)
order by NEWID() ) as a이 말씀 같습니다~!
-
렌슈유
2015.09.10 18:32
select * from(
select * from
(select top 6 * from 입출금 where 결과='완료' and 금액 between 100000 and 20000000 and type='입금' order by NEWID()) as b
union
select * from
(select top 4 * from 입출금 where 결과='완료' and 금액 between 100000 and 20000000 and type='출금'order by NEWID()) as a) as g
order by NEWID()이렇게 하니까 되네요 감사합니다
테이블변수에 담아 select 시키면 되지 않을까요.....음...