分享一些数据库的操作

安装mysql教程:

https://www.cnblogs.com/wanglei-xiaoshitou1/p/9406652.html

Select distinct:查询表中不同的值

 

INSERT INTO:往数据库中添加表或字段,值;有两种格式

  1. INSERT INTO table VALUES (value1,value2);
  2. INSERT INTO table (column1,column2(//字段的意思)) VALUES(value1,value2);

 

UPDATE:更新已存在表中的记录

UPDATE table SET column=value WHERE other_column=other_value;

 

DELETE:用于删除表中的记录

DELETE FROM  table WHERE other_column=other_value;

 

SELECT TOP:用于规定要返回的记录的数目(在mysql中也可用limit代替,oracle可以用rownum代替),对于大量数据非常有作用。

1.SQL SERVER:select top number|precent column from table;

2.MYSQL: select * from table limit 5;

3.ORACLE: select * from table where rownum<= 5;

 

LIKE: 查询在where子句中相似的值

Select * from table where name like ‘G%’;  //查询表中G开头的数据

 

SQL通配符:用于代替字符串的任何其他字符

%:代替0个或多个字符

_:代替一个字符

 

IN:查询where子句中对应的值

Select * from table where name in(‘1’,’2’);  //查询name为1或2的信息

IN与=的相同:均在where中使用作为筛选条件之一、都是等于的意思

不同: IN可以规定多个值,=只能规定一个值

 

BETWEEN:筛选两个值之间的数据范围内的值,可以为数值、文本或日期

1 .Select * from table where num between 1 and 2; //查询num1与20之间数据

2 .NOT BETWEEN:select * from table where num not between 1 and 20; //不在↑之间

3 .带有IN的BETWEEN: //选择num在1与20之间但country不为usa的数据

Select * from table where (num between 1 and 20) and country not in (‘usa’);

 

别名:表 AS 别名 ; 数据 AS 别名

 

JOIN连接: 连接两个或多个表的行结合起来

INNER JOIN 与JOIN 相同

Select * from table1 inner join table2 on table1.name = table2.name;

LEFT JOIN:从左表返回所有的行,如果右表中没有则为空

Select * from table1 left join table2 on t1.name=t2.name;

 

RIGHT JOIN:与LEFT相似,只是返回右表的行

Select * from table1 right join table2 on t1.name = t2.name;

 

FULL OUTER JOIN:属于两个表的并集,只要数据在左或右表中有一个,则返回行

Select * from t1 full outer join t2 on t1.name = t2.name;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值