$get_sql = "SELECT sql_calc_found_rows field1,field2 FROM table WHERE name = '1' order by add_time desc limit 2,20 "; $get_total_sql = "SELECT FOUND_ROWS() as total";…
SQL查询一个表中类别字段中Max()最大值对应的记录 SELECT A.id, A.name, A.version FROM DOC A, (SELECT id, MAX(version) AS version FROM DOC GROUP BY id) AS B WHERE A.id = B.id AND A.version = B.version…
表结构 then d.name else null end) 表名, a.colorder 字段序号,a.name 字段名, ( then '√'else '' end) 标识, (case when (SELECT count(*) FROM sysobjects WHERE (name in (SELECT name FROM sysindexes WHERE (id = a.id) AND (indid in (SELECT indid FROM sysindexkeys WHERE (i…
1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 代码如下: select * from people where peopleId in (select peopleId from people group by peopleId having count (peopleId) ) 2.删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录 代码如下: delete from people where peopleId…
<?php class czy { public $host="localhost"; //地址 public $uid="root"; //用户名 public $pwd="*******";//用户密码 public $dbname="*******";//用户数据库名 /** *给一个sql语句,返回执行的结果 *@param string @sql用户指定的sql语句 *@param int $type 用户给的…
SQL Server 获取数据的总记录数,有两种方式: 1.先分页获取数据,然后再查询一遍数据库获取到总数量 2.使用count(1) over()获取总记录数量 SELECT * FROM ( SELECT ROW_NUMBER() OVER(ORDER BY Id DESC) rn, ) OVER() AS TotalCount, Id FROM dbo.T_User )a WHERE a.rn 第二种方式既分页还能获取到总记录数量.就是多一个字段,如果获取一次数据较多的话,会浪费一些流量.…