I have a 3 tables, I need to apply sorting and pagination.
Create Table Interviews(
Id int primary key,
StartDate datetime2,
LocationName varchar(50),
)
Create Table Questions(
Id int primary key,
Title varchar(500)
)
Create Table Answers(
Id int primary key,
AnswerText varchar(500),
QuestionId int,
InterviewId int,
)
ALTER TABLE Answers ADD FOREIGN KEY (QuestionId) REFERENCES Questions(Id);
ALTER TABLE Answers ADD FOREIGN KEY (InterviewId) REFERENCES Interviews(Id);
I need to sort by (first name, age).
I tried:
SELECT *
FROM
(
SELECT a.Id,
a.AnswerText,
a.QuestionId,
a.InterviewId,
i.LocationName,
ROW_NUMBER() OVER (ORDER BY a.AnswerText) AS InterviewOrderNumber --Not correct
FROM Interviews i
LEFT JOIN Answers a
ON i.Id = a.InterviewId
) t
WHERE InterviewOrderNumber BETWEEN 1 AND 5
2条答案
按热度按时间0yg35tkg1#
https://dbfiddle.uk/LlBpd2x-
6ioyuze22#
I hope I understood correctly your question
You wanted to be sorted based on first name and age of the questions and then pageing the data based on that sorting