zoukankan      html  css  js  c++  java
  • Mysql 用法

    一转眼,一个星期过去了,来到测试班也一个星期了,今天经历了一次,这是自己这一周的总结,也算对自己这一周的一个交代。

    几个比较重要的语句:

    查看数据库

    show databases;  

    创建数据库

    create database student;

    删除数据库

    drop database student;

    进入数据库

    use student;

    查看表

    show tables;

    创建表"   字段 数据类型 约束条件, 主键。一个表由,字段,数据类型,约束条件组成。

    例如 create table stu(

    sno  int(11) primary key,

    name varchar(20),

    sex  varchar(10) default "

    age  int(11) default 10

    删除表

    drop table stu;

    查看表结构

    desc stu;

    数据的增删改查

    查询 selcet * from 表名

    条件查询

    Where后面跟条件  条件要写清楚

    例如,查询成绩表中成绩(degree)为92的信息

    Select * from score where degree =”92”;   

    查询成绩表中课程号是3-245并且成绩是86的信息

    Select * from score where cno='3-245' and degree=”86”或者用or  并且用and

    select * from teacher where tname = "李诚" and tsex = ""; 查找老师名字叫李诚并且性别是男的

    哪些列 哪个表 条件是 姓名为张三

    select * from student where name= “张三”;

    模糊查询  like    not like  后加% 

    查找老师表中姓李的 名字是两个字老师

    select * from teacher where tName like '%%'  

    %代表任意多个字符  _代表一个字符

    排序查询 order by 字段 排序值(desc(降序)/asc(升序)默认的是升序 )

    select * from student order by class asc   

    范围查询 关系运算符  between。。。and  .... 之间

    select * from Car where Price>=40 and Price<=60   这个小汽车的价格大于等于40小于等于60

    select * from Car where Price between 40 and 50  这个小汽车的价格在4050之间

    离散查询 in   not in

    select * from student where sname in ('张三','李四') 从学生里面查找名字叫张三,李四的

    Seclect * from student where sname =“张三” or  sname =“李四”

    重查询  distinct  不同的

    select distinct cno from score

     聚合函数,统计查询

    select sum(字段名) from  表名  查询所有价格之和 sum()求和

    select count(Code) from Car #查询数据条数

    select max(Code) from Car #求最大值

    select min(Brand) from Car #求最小值

    select avg(Price) from Car #求平均

    外层查询 (里层查询)  

    子查询的结果当做父查询的条件

    子查询:select Code from Nation where Name='汉族'

    父查询:select * from Info where Nation = ''

    select * from Info where Nation = (select Code from Nation where Name='汉族

    分页查询 limit 从第几条开始,取多少条数据

    #每页显示5条数据,取第5页的数据

    select * from student limit (pageSize-1)*5,5 

    分组查询   group by 字段  having 条件

    select

    count(*),cno,group_concat(degree),sum(degree)

    from score group by cno ;

    select cno,group_concat(degree),sum(degree) from score group by cno having count(*)>3

    #分组之后根据条件查询使用having 不使用where

                                

  • 相关阅读:
    ionic app打包和签名
    js时间戳与日期格式的相互转换
    js获取选中日期的当周的周一和周日
    Error occurred during initialization of VM Could not reserve enough space for 2097152KB object heap
    CSS媒体查询 @media
    [ng:areq] Argument 'XXXXCtrl' is not a function, got undefined
    plsql如何导出查询结果
    angularjs的$http请求方式
    JQuery请求数据的方式
    后台返回xml格式转json
  • 原文地址:https://www.cnblogs.com/wangrongchen/p/7788717.html
Copyright © 2011-2022 走看看