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语句学习,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。