需求很简单:假设有一个user表,表中实际上有10000条数据,但是我不知道有多少条,我要从数据库中每次取20条数据显示,那么怎么完成呢? 方案一: 首先执行一个 select count(*) as total from user; 上面SQL语句会查出总的记录条数.另外一点,可能这里不只是无条件的查,如果是有条件的查,那么可以使用临时表 select count(*) from user where id>10; 或者 select count(*) from (select id,name…
--查询所有表名 select name from sysobjects where xtype='u' select * from sys.tables --查询所有表名及对应架构 select t.[name] as tablename, s.[name] as [schema] from sys.tables as t,sys.schemas as s where t.schema_id = s.schema_id --查询数据库中所有的表名及行数 SELECT a.name, b.row…
分组后,统计记录条数: SELECT num,count(*) AS counts from test_a GROUP BY num; 查询结果如下: 对num去重后的数量的统计: SELECT count(t.counts) FROM ( SELECT num,count(*) AS counts from test_a GROUP BY num ) AS t; SELECT count(DISTINCT num) AS count FROM test_a; 它俩结果一样,都是5:只是一个是子…