| |

VerySource

 Forgot password?
 Register
Search
View: 1218|Reply: 8

Find the result of the result set!

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-3 21:00:01
| Show all posts |Read mode
If I get the corresponding ten data from the selection in a table, the second time I want to randomly take five data from the result of the first result set, I wonder how to write it like this, is there a function! ?? Thank you guys!
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-3-21 17:00:01
| Show all posts
select top 5 * from (select * from table) t order by newid ()
Reply

Use magic Report

0

Threads

49

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-3-21 18:30:01
| Show all posts
select top 5 *
from
(Your query) tt
order by newid ()
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 Italy

Post time: 2020-3-21 19:30:02
| Show all posts
use pubs
go
select top 5 * from
(
select top 10 title_id from titles
) a order by newid ()
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-3-21 20:00:02
| Show all posts
The top 5 can only take the first five, if it can be repeated ... how to write a statement !?
Reply

Use magic Report

0

Threads

49

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-3-21 20:30:01
| Show all posts
You can also modify your query directly

select top 5 ...
from a, b, c ...
where ...
order by newid ()
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-3-21 23:45:01
| Show all posts
Add this order by newid ()
It's just random ...
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-3-22 07:45:01
| Show all posts
Similarly top 1 five times and then union all
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-3-25 06:30:01
| Show all posts
select top 5 * from
(
select top 10 * from tbname
t order by newid ()
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list