zoukankan      html  css  js  c++  java
  • mysq笔记

    create database if not exists test; 为了不产生错误,创建数据库时加上一些 简单的逻辑判断

    drop database if exists test; 为了不产生错误,在删除数据库时加上一些简单的逻辑判断

    show database; 查看数据库列表

    create  table  if not exists test(id varchar(32)); 为了不产生错误,在创建表格时加上一些简单的逻辑判断

    drop table test; 删除表格

    insert into table_name(id,...,...)values(1,...,....),(2,...,...); 向表格内插入数据

    schemata 所有的库

    tables  所有的表

    columens  所有的列

    select * from user where name ='XXX‘;

    select * from user(表名) where(+条件) id = '1' and  name = 'lisi';

    select * from user  where  xxx and xxx or xxx;

    and  : true ,false ,数字,null,条件语句

       = ,!=,<,>,<>,like+(%)模糊查询

    select count(*) as(重命名) 'xxx',列名,222 from user where name = 'xxx'; 查询条数

    select conat(id,name) from user where id; 拼接

    select substr(列名,起始位置,偏移量) from user where id=1;截取字符串

    select length(name) from user where id=1; 字符串的位数

    select substr(name,length(name)-2,3) from user;

    select substr (name,-3,1) from user; 截取倒数第三位

    select min(id) from user; 取列内最小值

    select avg(id) from user; 取列内平均值

    select sum() from user; 取列内所有值之和

    select group_concat(name) from user; 把一列全部列出

    字符串函数

    select ascii();ascii函数

    select left(str,x);返回str字符串中最左边的x个值

    select position(int in substr);第一个字符串在第二个的哪个位置

    控制流函数

    select case when 1>0 then 'big' else 'small' end; 如果1>0 则输出 big 否则 输出 small

    select if(1>0,1,2);如果1>0输出1,否则输出2

    联合查询

    join 内关联

    left join 左关联

    right join 右关联

    inner join 内关联

    xxx  union  xxx

    查询列的个数必须一致 union select  生成一个临时表

    select name,grade from user u left join grade g on u.id=g.user_id; 把user中的name和grade中的grade用left join(左关联)关联起来,用的是id

    select * from user order by name; 按照名字排序  asc 升序  aesa 降序

  • 相关阅读:
    javascript基础之两种函数的定义方法
    与input有关的一些操作
    SpringMVC(八) RequestMapping HiddenHttpMethodFilter
    SpringMVC(七) RequestMapping 路径中带占位符的URL
    SpringMVC(六) RequestMapping 路径中ant风格的通配符
    SpringMVC(五) RequestMapping 请求参数和请求头
    SpringMVC(四) RequestMapping请求方式
    SpringMVC(三) RequestMapping修饰类
    SpringMVC(二) SpringMVC Hello World
    SpringMVC(一) SpringMVC概述
  • 原文地址:https://www.cnblogs.com/Blizzard-player/p/8857744.html
Copyright © 2011-2022 走看看