sql语句学习

select top 1 id from AddWorkFlow order by id desc
返回查询结果中前几条数据

select count(1) as total from Base_Users where DeptId=‘101010102‘ and iDel=0
返回查询的记录个数

select max(UserId) as total from Base_Users where DeptId=‘101010102‘ and iDel=0
返回查询内容的最大值或最大长度


select m.ModuleCode as cModuleCode,LEN(m.ModuleCode) AS [Length],m.ModuleName as cModuleName
,‘00000000000‘ AS cPower FROM Menu AS m ORDER BY CAST(m.ModuleCode AS INT)
CAST表示将里面的内容转化为对应的数据类型


JOIN 分为内连接,外连接(左外连接,右外连接,全外连接)

内连接: SELECT A.* FROM A INNER JOIN B ON A.ID=B.ID
SELECT a.cCardNo, a.cDoorId, a.cTimeId, b.vEmp_name, b.vDepart, b.dEndDate
FROM MJ_MacPower AS a INNER JOIN
Employee AS b ON a.cCardNo = b.vCardNo


左外连接: SELECT A.* FROM A LEFT JOIN B ON A.ID = B.ID

右外连接: SELECT A.* FROM A RIGHT JOIN B ON A.ID = B.ID

全外连接: SELECT A.*, B.* FROM A FULL OUTER搜索 JOIN B ON A.ID = B.ID

sql语句学习,布布扣,bubuko.com

sql语句学习

上一篇:编译安装Mysql与管理(十四)


下一篇:高可用集群(HA)之Keeplived原理+配置过程