你会用到的sql语法

2014-11-24 08:36:12 ? 作者: ? 浏览: 2

你会用到的sql语法
1、返回20%的数据
www.2cto.com
Select top 20 percent * from students
2、Sum 总数 :select sum(score) from students 计算学生的总分
Avg 平均值:select avg(score) from students 计算学生的平均分
Max 最大值:select Max(score) from students 计算学生的最高分
Min 最小值:select Min (score) from students 计算学生的最低分
3、查询奇数列和偶数列汇总
Select sum(表A) from students where ID%2 <> 0
Select sum(表A) from students where ID%2 = 0
4、随机取出5条数据 newid(),这个函数总是能返回一个新的GUID号码
Select top 5 * from students order by newid()
5、删除重复列的数据 distinct
select distinct year(createdate) from students
6、统计一个 数据库中有多少张表
select count(*) from sysobjects where xtype='U'
7、列出数据库里所有的表名
select name from sysobjects where type='U'
8、查看硬盘分区
EXEC master..xp_fixeddrives
-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: