ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

SQL语句

2021-08-31 16:01:53  阅读:294  来源: 互联网

标签:语句 alexa name country SQL where select


数据库A表   1 查询-select 1.1 select 语句1:select * from A 结果1:打印所有数据 语句2:select name from A 结果2:打印name一列的所有数据   1.2 select distinct 语句:select distinct country from A 结果:打印country列唯一不同的值,去掉重复值,打印的实际结果为第1、2行   2 条件-where 2.1 where 语句1:select * from A where country='USA' 结果1:打印country为USA的所有数据 语句2:select * from A where id=1 结果2:打印id为1的所有数据 运算符:=、<>(不等于)、>、<、>=、<=、between...and...(在某个范围内)、like(搜索某个模式)、in(指定针对某个列的多个可能值)   2.2 and & or 2.2.1 and 语句:select * from A where country='CN' and alexa>50 结果:打印country为CN并且alexa大于50的数据,打印的实际结果为第3行 2.2.2 or 语句:select * from A where country='CN' or alexa>50 结果:打印country为CN或者alexa大于50的数据,打印的实际结果为第2、3、4行 2.2.3 and & or 语句:select * from A where country='CN' and (alexa>50 or alexa>15 ) 结果:打印country为CN并且alexa大于50或大于15的数据,打印的实际结果为第4、5行   3 排序-order by 3.1 order by 语句:select * from A order by alexa 结果:打印按alexa列进行正序排序(正序:123456789) 3.2 order by desc 语句:select * from A order by alexa desc 结果:打印按alexa列进行降序排序(倒序:987654321) 3.3 order by 多列 语句:select * from A order by alexa,country 结果:打印按alexa列进行降序排序(优先对前面的进行排序,先按alexa排序后再按country)   4 新增-insert into 语句1:insert into A(name, url, alaxe, country) values ('百度', 'https://www.baidu.com/', '4', 'CN') 结果1:新增一条数据,id为自增故不用写入 语句2:insert into A(name, url, country) values ('stackoverflow', 'http://stackoverflow.com/', 'IND') 结果2:新增一条数据,id为自增故不用写入,alexa不写入则为0(数字为0、字符为null)   5 修改-update 语句1:update A set alexa=15, country='USA' where name='百度' 结果1:修改name为百度的数据,修改后alexa为15、country为USA 语句2:update A set alexa=15, country='USA' 结果2:不带条件语句,则将所有的alexa改为15、country改为USA   6 删除-delete 语句1:delete from A where name='百度' 结果1:删除name为百度的所有数据 语句2:delete from A / delete * from A 结果2:删除所有数据   7 选取条数-limit、top、rownum MySQL语句(limit):select * from A limit 5 SQL Server语句(top):select top 5 from A (top 50 percent/前50%) Oracle语句(rownum):select * from A where rownum<=5 结果:查询前五条数据   8 包含/不包含模式查询-like 8.1 包含模式 语句1:select * from A where name like '百%' 结果1:查询name以“百”字开头的数据 语句2:select * from A where name like '%百%' 结果2:查询name有“百”字的数据 8.2 不包含模式 语句1:select * from A where name not like '百%' 结果1:查询name不以“百”字开头的数据 语句2:select * from A where name not like '%百%' 结果2:查询name没有“百”字的数据   9 通配符 9.1 % 语句1:select * from A where url like 'http%' 结果1:查询 url 以字母 "https" 开始的所有数据 语句2:select * from A where url like '%oo%' 结果2:查询 url 包含 "oo"的所有数据 9.2 _ 语句1:select * from A where name like '_oogle' 结果1:查询name以一个任意字符开始,然后是 "oogle" 的所有数据 语句2:select * from A where name like 'G_o_le' 结果2:查询name以 "G" 开始,然后是一个任意字符,然后是 "o",然后是一个任意字符,然后是 "le" 的所有数据 9.3 [charlist] (MySQL 中使用 REGEXP 或 NOT REGEXP 运算符 (或 RLIKE 和 NOT RLIKE) 来操作正则表达式) 语句1:select * from A where name regexp '^[GFs]' 结果1:查询name 以 "G"、"F" 或 "s" 开始的所有数据 语句2:select * from A where name regexp '^[A-H]' 结果2:查询name 以 A 到 H 字母开头的    

标签:语句,alexa,name,country,SQL,where,select
来源: https://www.cnblogs.com/liujy111/p/15210751.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有