sql常用语句

常用sql语句
创建库creat database database-name
删除库drop database dbname
创建表create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],…)
删除表drop table tabname
添加列Alter table tabname add column col type
添加主键Alter table tabname add primary key(col)
创建视图create view viewname as select statement
删除视图drop view viewname
–查询:select * from table1 where 范围
–插入:insert into table1(field1,field2) values(value1,value2)
–删除:delete from table1 where 范围
–更新:update table1 set field1=value1 where 范围
–查找:select * from table1 where field1 like ’%value1%’ —like的语法
–排序:select * from table1 order by field1,field2 [desc]
–分组:select sex,sum(*) from table1 where age>20 group by sex
–总数:select count as totalcount from table1
–求和:select sum(field1) as sumvalue from table1
–平均:select avg(field1) as avgvalue from table1
–最大:select max(field1) as maxvalue from table1
–最小:select min(field1) as minvalue from table1
–between用法:select * from table1 where time between time1 and time2
–in用法:select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值