简单的查询语句2

USE demo
go
select * from text

--【1】在查询中使用常量列 :方便统计 增加列名年级,统一内容初一
select id 用户号, age 年龄,sex 性别,'初一' AS 年级 from text

--【2】查询返回限制的行数。使用top关键字
--(1)返回限定个数 限定出现两条数据,均为女生
select top 2 name AS 名字,age AS 年龄 from text where sex='女'
--(2)返回限定百分比20% PERCENT
select top 50 PERCENT name AS 名字,age AS 年龄 from text where sex='女'

原文地址:https://www.cnblogs.com/tangtangsimida/p/9478763.html