php主要实现B/S

.net IIS java TomCat

LAMP: Linux 系统 A阿帕奇服务器 Mysql数据库 Php语言(KE)

mysql:c常用代码

create table ceshi1
(
uid varchar (50) primary key,
pwd varchar (50),
name varchar (50),
nation varchar (50),
foreign key (nation) references nation(code)
)

写查询语句需要注意:

1,创建表的时候,最后一列后面不要写逗号

2,如果有多条语句一起执行,注意在语句之间加分号分隔

3,写代码时所有的符号都是半角的

关系型数据库:表和表之间是有关系存在的

创建表的几个关键字:

1,主键: primary key

2,非空:not null

3,自增长列:auto_increment

4,外键关系: foreign key (列名) references 表名(列名)

CRUD操作

1,添加数据
insert into info values("","","",) 要求values括号里面的值得个数要和表里面的列数相同

insert into info (code,name) values ("","") 添加指定列的值

2,修改数据

update info set name = "张三" where code="poo1"

3,删除数据

delete from info where code = "poo1"

4,查询数据

1.普通查询,查所有的

select * from info #查所有数据

select code,name from info #查指定列

2.条件查询

select * from info where code = "poo1" #一个条件

select * from info where name = "张三" and nation = "n001"

#两个条件并的关系

select * from info where name = "张三" or nation = "n001"

#两个条件或的关系

3.排序查询

select * from info order by birthday #默认升序排列 asc ;降序排列 desc

select * from car order by brand asc, oil desc #多列排序

4.聚合函数

select count(*) from info #q取个数

select sum(price) from car #查询price列的和

select avg(price) from car #查询price列的平均值

select max(price) from car #查询price列的最大值

select min(price) from car #查询price列的最小值

5.分页查询

select * from car limit (n-1)*5,5 #跳过 (n-1)*5 条数据取 m 条数据

6.分组查询

select brand from car group by brand #简单的分组查询

select brand from car group by brand having count(*)>2

#查询系列里面车的数量大于2的系列

7.去重查询

select distinct brand from car

8.修改列名

select brand as "系列" from car

9.模糊查询

select * from car where name like "奥迪%" #%代表“奥迪”开头

select * from car where name like "%奥迪%" #包含“奥迪”

select * from car where name like "_奥迪%" #“奥迪”前只有一个

10.离散查询

select * from car where code in ("c001","c002","c003")

select * from car where code not in ("c001","c002","c003")

高级查询:

1.连接查询

select * from info,nation #得出的结果,称为笛卡尔积

select * from info,nation where info.nation = nation.code

join on 链接

select * from info join nation #join 链接,笛卡尔积

select * from info join nation on info.nation = nation.code

2.联合查询

select code,name from info
union
select code,name from nation #查询的列相同

3.子查询

1) 无关子查询
select code from nation where name = "汉族"
#去nation表中查汉族的民族代号

select * from info where nation = ()
#在info表中查询民族代号为上一个查询结果的所有信息

select * from info where nation = (select code from nation where name = "汉族" )

子查询 查询的结果被父查询使用,子查询可以单独执行的成为无关子查询

2) 相关子查询

select * from car where oil < (该系列的平均油耗)
#查询油耗小于该系列平均油耗的

select avg(oil) from car where brand = "值"
#查询某系列的平均油耗

select * from car a where oil < (select avg(oil) from car b where b.brand = a.brand)

mySQL笔记2的更多相关文章

  1. MySQL笔记汇总

    [目录] MySQL笔记汇总 一.mysql简介 数据简介 结构化查询语言 二.mysql命令行操作 三.数据库(表)更改 表相关 字段相关 索引相关 表引擎操作 四.数据库类型 数字型 字符串型 日 ...

  2. 涂抹mysql笔记-数据库中的权限体系

    涂抹mysql笔记-数据库中的权限体系<>能不能连接,主机名是否匹配.登陆使用的用户名和密码是否正确.mysql验证用户需要检查3项值:用户名.密码和主机来源(user.password. ...

  3. centos7.2下安装Mysql笔记

    centos7.2下安装Mysql笔记 安装 MySQL 适用于 CentOS 7.0 或以后版本: yum install mariadb mariadb-server 适用于 CentOS 6.8 ...

  4. MySQL笔记(六)游标练习

    23.3.1 Trigger Syntax and Examples 意义不明的几道练习,留着备用. 感觉不好写,而且难以调试..不知道以后会不会有实际的应用场景. 环境:MySQL 笔记(三)由 t ...

  5. mysql 笔记(一)

    mysql 笔记 预留 mysql> use mysql; mysql> grant all privileges  on *.* to root@'%' identified by &q ...

  6. 【MySQL笔记】SQL语言四大类语言

     SQL语言共分为四大类:数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL.   1. 数据查询语言DQL 数据查询语言DQL基本结构是由SELECT子句,FROM子句, ...

  7. Mysql 笔记二

    Mysql 笔记二 Mysql 笔记二 Table of Contents 1. 前言 2. Master Thread 工作方式 2.1. 主循环(loop) 2.2. 后台循(backgroup ...

  8. 深入浅出mysql笔记---1、mysql下载安装

    深入浅出mysql笔记---1.mysql下载安装 一.总结 一句话总结: linux下rpm安装即可 1.linux的wget命令作用? 下载文件的工具:比如wget http://cn.wordp ...

  9. 深入浅出mysql笔记---0、序

    深入浅出mysql笔记---0.序 一.总结 一句话总结: 心得:买书之前建议先找找电子书,纸质书太难带了 1.开源作用? 开源对mysql的发展至关重要 2.mysql在2002年就全面支持了事务, ...

  10. 最全mysql笔记整理

    mysql笔记整理 作者:python技术人 博客:https://www.cnblogs.com/lpdeboke Windows服务 -- 启动MySQL net start mysql -- 创 ...

随机推荐

  1. HDU3923-Invoker-polya n次二面体

    polya定理.等价类的个数等于∑颜色数^置换的轮换个数 不可翻转的串当中.直接计算∑m^(gcd(n,i)) ,这里gcd(n,i)就是第i个置换的轮换数. 翻转的情况再分n奇偶讨论. n次二面体都 ...

  2. jQuery ajax - get(),getJSON(),post()方法

    1)       jQuery ajax - get() 方法: $(selector).get(url,data,success(response,status,xhr),dataType) 参数 ...

  3. Grovvy之解析XML文件

    假设现有customer.xml 文件内容如下: <?xml version="1.0" ?> <customers> <corporate> ...

  4. UIScrollView和UIPageController

    实现代码: // // ViewController.m // UIpageControl // // Created by dllo on 16/3/10. // Copyright © 2016年 ...

  5. MyEclipse内存不足问题

    1.修改eclipse.ini 在Myeclipse安装目录下G:\MyEclipse8.5\Genuitec\MyEclipse 8.5有一个myeclipse.ini配置文件,设置如下: -vma ...

  6. G-nav-03

    /*dele masthead.css style*/.masthead .navigation .btn.btn-masthead.btn-apply:after { content: ''; di ...

  7. JS实现Ajax,Josn数据的序列化和反序列化---例: 省市区联动(包含get,post)

    服务器端相应JOSN数据   用到序列化和反序列化----命名空间using System.Web.Script.Serialization; public void ProcessRequest(H ...

  8. hdu5536 字典树xor

    一想到xor还要求最大类似的题,字典树效率高. 此代码c++ TLE. #include<stdio.h> #include<string.h> ; struct node { ...

  9. hdu1507二分匹配

    1 //hdu1507 挺不错的题 #include<stdio.h> #include<string.h> #define INF 99999999 struct node ...

  10. Java算法-快速排序

    快速排序也是用归并方法实现的一个“分而治之”的排序算法,它的魅力之处在于它能在每次partition(排序算法的核心所在)都能为一个数组元素确定其排序最终正确位置(一次就定位准,下次循环就不考虑这个元 ...