数据查询-列别名
//使用AS来命名列
SELECT SCode AS 学生编号,SName AS 学生姓名,
SAddress AS 学生地址
FROM Students
WHERE SAddress <> ‘河南新乡‘
//使用=来命名列
SELECT 姓名 = FirstName+‘.‘+LastName
FROM Employees
注意:
1. + 连接的数据类型必须兼容
2. 如果 + 连接字符型数据,结果为字符串数据的连接
3. 如果 + 连接数值型数据,结果为数值的和
数据查询-限制行数
//限制固定行数
SELECT TOP 5 SName, SAddress
FROM Students WHERE SSex = 0
//返回百分之多少行
SELECT TOP 20 PERCENT SName, SAddress
FROM Students WHERE SSex = 0
查询单列排序
//升序排列
SELECT StudentID AS 学生编号,(Score*0.9+5) AS 综合成绩
FROM Score
WHERE (Score*0.9+5)>60
ORDER BY Score
//降序排列
SELECT StudentID,Score FROM Score ORDER BY Score DESC
//按多列排序
SELECT StudentID AS 学生编号, CourseID AS 课程ID, Score AS 成绩
FROM Score
WHERE Score > 60
ORDER BY CourseID, Score
原文地址:https://www.cnblogs.com/wangzhaofang/p/8297956.html
时间: 2024-10-26 12:30:02