首页 > 其他 > 详细

py知识(每日更新) 7.31

时间:2019-08-09 19:26:00      阅读:60      评论:0      收藏:0      [点我收藏+]

单表的查询

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

py知识(每日更新) 7.31

原文:https://www.cnblogs.com/lyoko1996/p/11328890.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!