数据库的增删改查 insert delete update select

 

 

 

 

添加数据用:关键字insert

Insert into 表名(属性列1,属性列2)values(属性值,属性值)

用已有的数据表建立新的数据表

Create table 表名1 as select 属性列1,属性列2 from 表名

修改数据用:关键字update

Update  表名 set 属性列1=data1,属性列2=data2 [where  condition]

删除数据用:关键字delete

Delete from 表名[where condition ]

查询数据用:select

Select 属性列1  from table 表名 [where  condition]

   Select检索数据:简单检索,多表检索,where条件检索、子查询等等

Select

[distinct |all ]

属性列

From  table 表名

[where  condition]

[group by ]

[having  condition]

[order by ]

1.使用关键字as用来指定别名,select sno as 学号,sname as 姓名 from  student

2.使用表达式操作查询的字段,数据库中的数据不会被修改

  Select sname,2018-sage as 出生年月 from student

Select  sname, sage || '*' || 1.25 || '=' || sage*1.25 as new_age FROM STUDENT;

Select  sname,  sage*3 as new_age  FROM STUDENT;

3.使用函数操作查询的字段

1)对数据库中的字段进行截取操作substr()

  Select sname as 姓名,substr(sno,7,9)  as 截取的学号后三位  from  STUDENT;

4.去除检索数据中的重复数据

 Select distinct sno from student;

5.对检索出来的数据进行排序使用的关键字是order by

 1)按照年龄降序排列,不指定排序方式的话,默认是升序ASC

  Select * from student order by sage desc;

  ###排序时候对NULL值的处理:

  默认情况下,进行排序的时候将NULL值看成最大值。即升序的时候它在最后,降序的时候它在最首位。

指定的话, 用关键词NULLS  first和last

 Select * from student order by sage NULLS FIRST;

 Select * from student order by sage NULLS last;

2)使用别名作为排序字段:

 Select sname 姓名,sage 年龄 from student order by 年龄 NULLS FIRST;

3)使用表达式作为排序字段:

 Select sname 姓名,sage*3  from student order by sage*3 desc NULLS FIRST;

需要注意的是NULL*其他数值还是NULL

4)使用字段的位置作为排序字段:

Select * from student order by 4 NULLS FIRST;

这里字段的位置指的是属性列的位置,4指的是sage属性列的位置

5)使用多个字段混合排序:

多个字段排序的操作过程是:NO1.按照第一个字段排序;NO2.在此基础上,按照第二个字段排序;

Select * from student order by ssex  ASC, sage desc NULLS LAST;

6.使用where子句设置检索条件

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值