TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Praveen Kumar
284
6.6k
2.3m
How to group records where each group can have maximum 5 records
Jun 29 2020 3:47 AM
In SQL Server, I have to group records by a column where each group can have at most 5 records
To achieve it, I am using the following query which groups my data into two groups. Where the first group have more than 5 records. Kindly suggest me, how to set the limit.
Declare
@maxRecord
int
= 5
--where I can use it?
Declare
@
Table
Table
(Id
int
, Location
Int
)
insert
into
@
Table
Values
(1,1)
,(2,1)
,(3,1)
,(4,2)
,(5,2)
,(6,2)
,(7,2)
,(8,2)
,(9,1)
,(10,1)
,(11,1)
,(12,1)
Select
Id,Location,DENSE_RANK() Over(
Order
By
Location)
as
GroupNo
From
@
Table
Order
By
GroupNo
Reply
Answers (
1
)
When split comma separated to text and value not working
Can someone help me Query this