数据库的基本操作(二)
5.筛选
--top n (按个数筛选)
select * from UserInfo
select top 3 * from UserInfo
--top n percent * (按百分比筛选)
select top 20 percent * from UserInfo
--where (行筛选)
select * from UserInfo where UserId=1
--where (列筛选)
select UserName from UserInfo where UserId=1
6.排序
--排序(单重)
select * from UserInfo order by cid desc (--降序-desc,升序-asc)
--排序(多重)
select * from UserInfo order by cid asc,UserPwd desc
--(逗号前为主排序规则,逗号后为子排序规则,即如果前面的相同,则把相同的按照逗号后的规则进行排序)
7.Between ... and...语句
--取出编号从2到5的行
select * from UserInfo where UserId between 2 and 5
--取出cid编号为2或5的行
select * from UserInfo where cid in(2,5)