分享

SQL Server|排序查询及高级条件查询

 L罗乐 2018-10-07


——A·May

一起来学数据库

排序查询



9.22 查询忍者的姓名、生日和村落,并以生日升序排列

select name as 姓名, birth as 生日,depart as 村子 from hy  order by birth

#order by永远在最后


9.23 查询4个技能的忍者信息,包括姓名、生日和村落,并以生日升序排列

select name as 姓名, birth as 生日,depart as 村子 from hy where jn=4 order by birth


9.24 查询忍者所有信息并按照技能数降序排列

select * from hy order by jn DESC


9.25 查询忍者所有信息并以碎片数和技能数升序排列

select * from hy order by suipian,jn


9.26 查询忍者所有信息并以碎片数降序、技能数升序排列

select * from hy order by suipian DESC,jn


9.27 查询忍者信息,并以第一个字段,即姓名升序排列

select * from hy order by 1


9.28 查询前5个观测信息,并以姓名升序排列。类似于head()的作用

select TOP 5 * from hy order by 1


9.29 查询百分之十的观测信息,并以姓名升序排列。

select top 10 percent * from hy order by 1


高级条件查询


AND OR NOT LIKE IN 

9.30 查询所有木叶女性忍者,并按照技能数降序排列

select * from hy where depart='木叶' AND sex='女' order by jn desc

#不同字段的“所有”,用and


9.31 查询木叶和砂隐的忍者的姓名、技能和村子,并按照生日降序

select name as 姓名, jn as 技能, depart as 村子 from hy where depart='木叶'or depart='砂隐' order by birth

#同字段的“所有”,用or


9.32 查询出生时间不在1980-1990年之间的忍者的所有信息,并按照生日升序排列

select * from hy where birth not between '01/01/1980' and '12/31/1989'


9.32 查询技能数为4和5的忍者的信息,并以技能降序排列

select * from hy where jn=4 or jn=5 order by jn

select * from hy where jn in (4,5)

#同一字段,多条件用IN会更快一些


9.32 查询身高为178,177,182,183的忍者信息,并以身高降序排列

select * from hy where height in (178,177,182,183) order by height


9.33 查询佐助的不同形态信息

#模糊查询,常用的like%形式


我的SQL学习之路

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多