SQL学习一

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
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MyObject-C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值