如何爲年份前25名學生創建存儲過程。 所以PROC應該採取一年PARAM和回報,學生證, 和標誌的年度如何使用sqlserver中的參數創建存儲過程
Alter PROCEDURE getstudents
(
@year INT
)
AS
BEGIN
SELECT student-name FROM tbl_Students WHERE [email protected]
Thanks
如何爲年份前25名學生創建存儲過程。 所以PROC應該採取一年PARAM和回報,學生證, 和標誌的年度如何使用sqlserver中的參數創建存儲過程
Alter PROCEDURE getstudents
(
@year INT
)
AS
BEGIN
SELECT student-name FROM tbl_Students WHERE [email protected]
Thanks
嘗試這一個 -
ALTER PROCEDURE dbo.getstudents
@year INT
AS
BEGIN
SELECT TOP 25
student_name
, student_id
, marks = SUM(marks)
FROM dbo.tbl_Students
WHERE [Year] = @year
GROUP BY
student_name
, student_id
ORDER BY marks DESC
END
或者這 -
ALTER PROCEDURE dbo.getstudents
@year INT
, @count INT
AS
BEGIN
SELECT student_name, student_id, marks
FROM (
SELECT
student_name
, student_id
, marks
, rn = ROW_NUMBER OVER (ORDER BY marks DESC)
FROM (
SELECT
student_name
, student_id
, marks = SUM(marks)
FROM dbo.tbl_Students
WHERE [Year] = @year
GROUP BY
student_name
, student_id
) t
) t2
WHERE t2.rn <= @count
END
你以正確的方式傳遞的參數。現在
必須cange裏面你想要的信息SP查詢。
所以最後選擇顯示你已經提取出的結果。
顯然對經銷商的學生,學生的我等,你在這裏寫你的數據庫模型。
試試這個,對於今年的錯誤我得到
ALTER PROCEDURE getstudents
@year INT
AS
BEGIN
SELECT TOP 25 [student-name]
FROM tbl_Students WHERE [email protected]
END
無效的列名。 – kvs
對不起,我沒有水晶球。請爲您的桌子提供一個「DDL」。 – Devart