如何以下列格式编写sql查询 [英] how to write sql query in following format
本文介绍了如何以下列格式编写sql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT TOP 3 * FROM tbl_LectureScheduling
ORDER BY StartDateTime DESC
我在.NET中的.cs文件中编写SQL代码。所以我通常用以下格式编写代码:
SELECT TOP 3 * FROM tbl_LectureScheduling
ORDER BY StartDateTime DESC
I am writing SQL code in .cs file in .NET. So I am usually writing code in following format :
var query = from LectureAttendance in context.tbl_LectureAttendence
join LectureSchedulling in context.tbl_LectureScheduling on LectureAttendance.LectureScheduleID equals LectureSchedulling.LectureScheduleID
join Lectures in context.tbl_Lectures on LectureSchedulling.LectureID equals Lectures.LectureID
where LectureAttendance.StudentID == StudentID
select new
{
LectureAttendance.StudentID,
LectureAttendance.LectureScheduleID,
LectureAttendance.status,
LectureSchedulling.LectureID,
LectureSchedulling.StartDateTime,
Lectures.LectureName,
};
所以我不知道如何以这种格式编写上面的sql查询,因为这是.cs文件,它不支持像TOP这样的关键字和按顺序。
So I dont know how to write above sql query in this format as this is .cs file which does not support keywords like "TOP" and "Order By".
推荐答案
如需订购记录,请参阅此链接
LINQ中的SQL排序操作 [ ^ ]
AND For Top 3,5 .....
如果你写了查询结束想要获得前3名写作Take(3),如果你想取5条记录写下Take(5)
参考
举例 [ ^ ]
For Ordering the record refer this link
SQL Ordering Operation in LINQ [^]
AND For Top 3,5 .....
write end of the query if you want to get top 3 write Take(3), If you want to take 5 record write Take(5)
Refer
Take examples[^]
这篇关于如何以下列格式编写sql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文