SQL语句学习笔记(sql语言教程)
SQL语句的一些常用场景
1. where ... in ...查找固定的值,如查找table中id为1,2,3的数据行
select * from table
where id in (1, 2, 3);
2.table A left join table B on 条件
当满足条件的时候,将数据表B拼在数据表A上,如将table A和table B里id相同的数据行拼在一起,如果A有数据B没有则B对应的数据显示为空
select A.id from table A left join table B on A.id = B.id;
3.oracle数据库中left join的另外一种写法
select A.id from table A, table B where A.id = B.id(+);
4.date的处理方式,将取出的数据类型转换为想要的类型,如从table中选取今年2月份的数据
select * from table A where to_char(a.create_date, 'yyyymm')='202202';
注意:oracle中字符串表示的符号是单引号
5.多行注释
/*
123
*/
单行注释
--123