SQL学习一

来源:互联网 发布:魔兽世界5.4.8数据库 编辑:程序博客网 时间:2024/06/05 17:06

sql大小写不敏感


select:

select  * from 表名

select 列 from 表名



distinct :

select distinct 列 from 表名



where:

select 列 from 表名 where 列 操作符 值

where子句中使用

操作符描述=等于<>不等于>大于<小于>=大于等于<=小于等于BETWEEN在某个范围内LIKE搜索某种模式

select * from persons where city  = 'bj‘

SQL 使用单引号来环绕文本值(大部分数据库系统也接受双引号)。如果是数值,不要使用引号。



between and:

select distinct need from type where id between 10 and 15(包含情况视数据库而定)

select distinct need from type where id not between 10 and 15

select distinct need from type where name between 'abd' and 'c'




like:

select distinct need from type where name like '%d'(d结尾)

select distinct need from type where name like 'd%'(d开头)

select distinct need from type where name like '%d%'(包含d)

select distinct need from type where name not like '%d%'(包含d)




order by:

select distinct need from type order by id desc

select distinct need from type order by id asc,name desc(在第一列中有相同的值时,第二列是以升序排列的。如果第一列中有些值为 nulls 时,情况也是这样的。)




insert into:

insert into 表名 values(值1,值2,...)

insert into 表名 (列1,列2,...)values(值1,值2,...)




update:
语句用于修改表中的数据。

update 表名 set 列名 = 新值,列名 = 新值 where 列名 = 某值




delete:

语句用于删除表中的行。

delete from 表名 where 列名 = 值

delete from 表名 (删除所有行)


Top:

用于规定要返回的记录的数目。

select 列名 from 表名 limit 数目



通配符:

SQL 通配符必须与 LIKE 运算符一起使用。

通配符描述%替代一个或多个字符_仅替代一个字符[charlist]字符列中的任何单一字符

[^charlist]

或者

[!charlist]

不在字符列中的任何单一字符

select * from persons where city like 'n%'

select * from persons where city like '%n%'

select * from persons where city like '_nv'

select * from persons where city like '_nv_n_d'



in:

操作符允许我们在 WHERE 子句中规定多个值。

select * from persons where city in ('a','b')




alter table:

 语句用于在已有的表中添加、修改或删除列。


alter table 表名 add 列名 数据类型

alter table 表名 drop column 列名 



function:

count(*)获取数目,可以和where 组合

count(列名),count(distinct 列名)




0 0
原创粉丝点击