Last post Feb 27, 2018 06:16 AM by Angie xu - MSFT
Feb 24, 2018 06:07 AM|Rameezwaheed|LINK
I have below table data , Now i Have to write a query to select the records with distinct in near by column , there should be no same subject student near by each other . mean no adjacent column have the same subject student.
Required OUT PUT
Please suggest the way.
Feb 27, 2018 03:13 AM|Cathy Zou|LINK
I did not find the logical relationship between the result you wanted and the datasheet you provided, so can you give a detailed description of this?
For example, if you have more than one row or column, what will the result be?
Feb 27, 2018 05:11 AM|Rameezwaheed|LINK
Thank you Cathy Zou for your reply,
Basically I have different Students Enrolled in different Subjects , now i need to design sitting arrangement for them based on Room capacity. i have one table with students and their subjects enrolled. like
Feb 27, 2018 06:16 AM|Angie xu - MSFT|LINK
DECLARE @Tmp TABLE ([Subject A] VARCHAR(20),[Subject B] VARCHAR(20))
insert into @Tmp values
('H','P');with a as
select *,ROW_NUMBER() over(order by [Subject A]) as rownum
select *,ROW_NUMBER() over(order by[Subject A]) as row1 from a where rownum<=4
select *,ROW_NUMBER() over(order by[Subject A]) as row2 from a where rownum>4
b.[Subject A] as col1,
b.[Subject B] as col2,
c.[Subject A] as col3,
c.[Subject B] as col4 from b join c on b.row1=c.row2