0
A
回答
1
--Create the table on the fly with the condition stated
SELECT
TEAM_NAME,
RACES_COMPETED
INTO [TOP TEAMS]
FROM YourTable
WHERE RACES_COMPETED >= 500 and RACES_COMPETED <= 900
--Store the number of teams in the new table in a variable for ease of use
DECLARE @topTeams INT
SET @topTeams = (SELECT COUNT(*) FROM [TOP TEAMS])
--If there are teams in the table, print the number of teams. If there aren't any, print the other statment
IF @topTeams > 0
BEGIN
SELECT 'NO. OF TOP TEAMS: ' + CAST(@topTeams AS VARCHAR)
END
ELSE
BEGIN
SELECT 'NO TOP TEAMS EXIST'
END
是使用TEMP TALBE的相同代碼
--Drop the TEMP TABLE if it exists
IF OBJECT_ID('tempdb..#TOP_TEAMS') IS NOT NULL DROP TABLE #TOP_TEAMS
--Create the table on the fly with the condition stated
SELECT
TEAM_NAME,
RACES_COMPETED
INTO #TOP_TEAMS
FROM YourTable
WHERE RACES_COMPETED >= 500 and RACES_COMPETED <= 900
--Store the number of teams in the new table in a variable for ease of use
DECLARE @topTeams INT
SET @topTeams = (SELECT COUNT(*) FROM #TOP_TEAMS)
--If there are teams in the table, print the number of teams. If there aren't any, print the other statment
IF @topTeams > 0
BEGIN
SELECT 'NO. OF TOP TEAMS: ' + CAST(@topTeams AS VARCHAR)
END
ELSE
BEGIN
SELECT 'NO TOP TEAMS EXIST'
END
+1
非常感謝。非常感謝 –
相關問題
- 1. 創建if語句
- 2. 隱藏表單並使用if語句
- 3. 創建複查if語句
- 4. 在if語句中使用if語句的建議
- 5. 用if語句創建對象
- 6. 使用if if語句檢查列表
- 7. 使用if ... else if ... else語句創建一個向量R
- 8. 如何使用if語句創建表格來求和值並評估結果?
- 9. 使用if語句
- 10. 使用「if語句」
- 11. 使用if語句
- 12. 使用if語句
- 13. 創建if語句與浮動
- 14. MySQL IF語句程序創建錯誤
- 15. 創建優雅的if語句
- 16. 在登錄時創建if語句?
- 17. 爲datagrid值創建一個IF語句
- 18. 在mysql語句中使用if語句
- 19. 在for語句中使用if語句
- 20. 在Linq語句中使用'if'語句
- 21. if語句後使用switch語句
- 22. 在if語句中使用where語句
- 23. 在If語句中使用CountIf語句
- 24. 在「With」語句中使用「IF」語句
- 25. PostgreSQL創建子表並使用子句
- 26. 檢查UserDefaults的值並創建一條IF語句
- 27. 使用if語句遍歷列表
- 28. 使用if語句更新sql表格
- 29. ASH if if語句中的if語句
- 30. 在jQuery中使用if語句創建函數
讓我先說這不是現實世界的情景,但我想他們試圖讓你應用不同的概念。你對這個問題的理解有什麼困難?簡而言之,他們要求您獲取RACES_COMPLETED在500到900之間的所有行,這是一條基本的SELECT語句。你對SQL Server有什麼經驗? – bassrek
沒有太先進,但我理解得很好 –
我認爲有人希望您使用SQL Server Management Studio將某些行選入臨時表中。打印消息需要另一個SQL語句。還有其他的可能性。 –