2020-01-07 基础查询

查询列

select <列名1,列名2> from <表名>;

查询所有列

select * from <表名>;

显示别名

select <列名1> as <别名>, <列名2> as <别名2> from <表名>;

查询常数

select 'xx' as string from <表名>;

去除重复数据

select distinct <列名> form <表名>;

select distinct <列名1>,<列名2> from <表名>;

NULL也会被去重

where 条件选择

select <列名> from <表名> where <条件表达式>;


单行注释:--xxxxxx

多行注释:/* xxxxx */


条件表达式:算术运算符、比较运算符、逻辑

select <列名>, <列名> * 2 as <别名> from <表名>;

四则运算的运算符: + - * /

所有包含NULL的计算结果都为NULL

select <列名> > 100 from <表名>;

比较运算符:= <> > >= < <=

不能对NULL使用比较运算符

使用NULL使用特有的运算符

select <列名> is null from <表名>;

select <列名> is not null from <表名>;

逻辑运算符:not and or

可以使用括号提高运算符优先级

sql语句有自己的运算优先级

你可能感兴趣的:(2020-01-07 基础查询)