zoukankan      html  css  js  c++  java
  • sql 查询语句

    1.

    select * from 表名

    select distinct 查询列表 from 表名    //去重查询

    查表结构: DESC departments;

    去重查询:select distinct location_id from departments;

    字符拼接查询: select concat (字符1,字符2,字符3...);

    ifnull函数:select ifnull(commission_pct,0) from employees;  判断某字段或表达式是否为null, 如果是null,返回指定的值,否则返回原本的值。

    isnull:select isnull(commission_pct),commission_pct from employees;   判断某字段或表达式是否为null,如果是,则返回1,否则返回0.

    2. 条件查询

    select 查询列表 from 表名 where 筛选条件;

    select * from employees where salary>12000;

    select last_name, department_id from emplyees where department_id!=90;

    select last_name,salary,commission_pct from emplyees where salary>=10000 and salary<=20000;

    select last_name,salary,commission_pct from emplyees where salary between 10000 and 20000;

    select last_name,salary,commission_pct from emplyees where commission_pct is null;

    select last_name,salary,commission_pct from emplyees where commission_pct <=>null;

    select last_name,salary,commission_pct from emplyees where commission_pct is not null;

    select * from employees where last_name like '%a%';

    select * from employees where last_name like '___e_a%';

    select * from employees where last_name like '_\_%';  第2个字符为_时,需要作用转义符。

    select * from employees where last_name like '_$_%' escape '$';  指定$为转义符。

    select last_name,job_id from employees where job_id='IT_PROT' or job_id='AD_VP' or job_id='AD_PRES';

    select last_name,job_id from employees where job_id in ('IT_PROT','AD_VP','AD_PRES');

    按条件表达式筛选:

      条件运算符:>   <   =   !=    <>   >=   <=

    按逻辑表达式筛选:

    作用:用于连接条件表达式

    &&和and:两个条件都为true,结果为true, 反之为false

    ||和or:

      逻辑运算符: &&  ||   !    and   or   not

    模糊查询:

      like(和通配符搭配使用 % 0个或任意多个字符,_任意单个字符)  between and  in(列表中的值需要一致或兼容)  is null(=或<>不能用于判断null值, 仅用于判断null值,可读性高)  is not null

    安全等于  <=>   不仅用于判断null值,还可以判断普通数据,可读性不高。

    mysql 服务的启动,停止

    方式一:命令行:

    net start 服务名

    net stop 服务名

    方式二:计算机--右击--管理--服务

    Mysql服务的登录和退出

    登录:mysql [-h 主机名 -P 端口号] -u 用户名 -p密码  h和主机名间可有可没有空格,P和端口号间可有可无空格,u和用户名间可有可无空格,p和密码间不需要空格

    退出:exit或ctrl+C

  • 相关阅读:
    Java将对象保存到文件中/从文件中读取对象
    Python爬虫框架--Scrapy安装以及简单实用
    Python--网络爬虫模块requests模块之响应--response
    用Pycharm创建指定的Django版本
    python网络爬虫之requests模块
    Python---异常处理
    Python函数的装饰器修复技术(@wraps)
    Django Rest framework
    Vue的基础使用
    Vue
  • 原文地址:https://www.cnblogs.com/misswjr/p/9442422.html
Copyright © 2011-2022 走看看