py知识(每日更新) 7.31

单表的查询

select * from 表名;
select 字段名 from 表名;
select 字段名,字段名,字段名 from 表名;

select distinct 字段 from 表;
# 对查出来的字段进行去重

select emp_name,salary*12 from 表
# 字段salary参与了四则运算
例如:# select concat(字段,'字符串2',字段) from 表
    # select concat(emp_name,' : ',salary) as info from employee;
    # select concat(emp_name,' : ',salary) info from employee;
    # select concat_ws('分隔符',字符串,字段1,字段2) info from employee;
    # select concat_ws('|','信息',emp_name,salary) info from employee;

case when语句 类似于嵌套if
select(
    case
    when emp_name = 'alex' then
        concat(emp_name,'BIGSB')
    when emp_name = 'jingliyang' then
        emp_name
    else
        concat(emp_name,'sb')
    end
    ) as new_name
from employee;

where筛选条件

where 筛选行
select * from 表 where 条件
# 范围查询
    # > < >= <= = !=/<>
    # between a and b
    # in (1,2,3,4)   n选1
# 模糊查询
    # like
    # % 一个百分号代表任意长度的任意字符
        # 'a%'
        # '%ing'
        # '%a%'
    # _ 一个下划线代表一个任意字符
         # 'a__'
    # regexp
         # '^a'
         # '\d+'
    # is is not
         # is null
         # is not null
   # 逻辑运算
        # and
        # or
        # not

猜你喜欢

转载自www.cnblogs.com/lyoko1996/p/11328890.html