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. ASP.NET if语句创建div
- 4. 创建复查if语句
- 5. 使用嵌套if语句创建公式创建
- 6. 在if语句中使用if语句的建议
- 7. 用if语句创建对象
- 8. 创建一个if语句用CSS
- 9. 使用if ... else if ... else语句创建一个向量R
- 10. 使用if if语句检查列表
- 11. 如何使用if语句创建表格来求和值并评估结果?
- 12. 使用if语句
- 13. 使用“if语句”
- 14. 使用if语句
- 15. 使用if语句
- 16. 使用if语句
- 17. 使用if语句
- 18. MySQL IF语句程序创建错误
- 19. geoTest函数 - 创建if/else语句
- 20. 你如何创建多个“if”语句?
- 21. 创建一个if语句变量
- 22. 在IF语句中创建变量
- 23. 在WHMCS中创建{if}语句
- 24. 创建if语句与浮动
- 25. 创建优雅的if语句
- 26. 为datagrid值创建一个IF语句
- 27. 在if语句中创建一个'或'
- 28. 在登录时创建if语句?
- 29. 在C++中创建if else语句
- 30. 在if/else语句中创建循环
让我先说这不是现实世界的情景,但我想他们试图让你应用不同的概念。你对这个问题的理解有什么困难?简而言之,他们要求您获取RACES_COMPLETED在500到900之间的所有行,这是一条基本的SELECT语句。你对SQL Server有什么经验? – bassrek
没有太先进,但我理解得很好 –
我认为有人希望您使用SQL Server Management Studio将某些行选入临时表中。打印消息需要另一个SQL语句。还有其他的可能性。 –