MySQL 基础之 单表、多表联查

目录

  • 使用和不使用not null 的区别:

    • 不使用: 查询时用‘name is null’ 作为条件
    • 使用:查询时用‘name=’‘ ’作为查询条件
  • 单表操作:
    • 单表查询的语法:

      • 分组:group by
      • having:
      • order by: order by 字段名 asc(升序)/desc(降序)
      • limit 分页: limit offset, size
  • 多表操作
    • 外键: 占用空间少,方便修改数据

      • 一对多:
      • 多对多:
      • 一对一:
      • 多表联查:

使用和不使用not null 的区别:

不使用: 查询时用‘name is null’ 作为条件

mysql>create table t8(
    -> id int auto_increment primary key,
    -> name varchar(32),
    -> email varchar(32)
    -> )charset=utf8;

mysql>insert into t8(email) values ('allen');

mysql> select * from t8;
+----+------+-------+
| id | name | email |
+----+------+-------+
|  1 | NULL | allen |
+----+------+-------+
1 row in set (0.01 sec)

mysql> select * from t8 where name is null;
+----+------+-------+
| id | name | email |
+----+------+-------+
|  1 | NULL | allen |
+----+------+-------+
1 row in set (0.00 sec)

使用:查询时用‘name=’‘ ’作为查询条件

mysql> create table t9(
    -> id int auto_increment primary key,
    -> name varchar(32) not null default '',
    -> email varchar(32) not null default ''
    -> )charset=utf8;

mysql> insert into t9 (email) values ('allen');

mysql> select * from t9;
+----+------+-------+
| id | name | email |
+----+------+-------+
|  1 |      | allen |
+----+------+-------+
1 row in set (0.00 sec)

mysql> select * from t9 where name='';
+----+------+-------+
| id | name | email |
+----+------+-------+
|  1 |      | allen |
+----+------+-------+
1 row in set (0.01 sec)

单表操作:

单表查询的语法:

select 字段1,字段2 from 表名
                        where 条件
                        group by field
                        having 筛选
                        order by field
                        limit 限制条数

分组:group by

分组指的是:

将所有记录按照某个相同字段进行归类,比如针对员工信息表的职位分组,或者按照性别进行分组等

用法:select 聚合函数,字段名 from 表名 group by 分组的字段;

group by 是分组的关键词, 必须和聚合函数 一起出现

where 条件语句和groupby分组语句的先后顺序:
where > group by > having(*********)

例子:

创建表:

create table emp(
id int not null unique auto_increment,
name varchar(20) not null,
gender enum('male','female') not null default 'male', #大部分是男的
age int(3) unsigned not null default 28,
hire_date date not null,
post varchar(50),
post_comment varchar(100),
salary double(15,2),
office int, #一个部门一个屋子
depart_id int
);

插入内容:

insert into emp(name,gender,age,hire_date,post,salary,office,depart_id) values
('egon','male',18,'20170301','老男孩驻沙河办事处外交大使',7300.33,401,1), #以下是教学部
('alex','male',78,'20150302','teacher',1000000.31,401,1),
('wupeiqi','male',81,'20130305','teacher',8300,401,1),
('yuanhao','male',73,'20140701','teacher',3500,401,1),
('liwenzhou','male',28,'20121101','teacher',2100,401,1),
('jingliyang','female',18,'20110211','teacher',9000,401,1),
('jinxin','male',18,'19000301','teacher',30000,401,1),
('成龙','male',48,'20101111','teacher',10000,401,1),

('歪歪','female',48,'20150311','sale',3000.13,402,2),#以下是销售部门
('丫丫','female',38,'20101101','sale',2000.35,402,2),
('丁丁','female',18,'20110312','sale',1000.37,402,2),
('星星','female',18,'20160513','sale',3000.29,402,2),
('格格','female',28,'20170127','sale',4000.33,402,2),

('张野','male',28,'20160311','operation',10000.13,403,3), #以下是运营部门
('程咬金','male',18,'19970312','operation',20000,403,3),
('程咬银','female',18,'20130311','operation',19000,403,3),
('程咬铜','male',18,'20150411','operation',18000,403,3),
('程咬铁','female',18,'20140512','operation',17000,403,3)
;
1、select count(id), gender from emp group by gender;

以性别为例, 进行分组, 统计一下男生和女生的人数是多少个:

+-----------+--------+
| count(id) | gender |
+-----------+--------+
|        10 | male   |
|         8 | female |
+-----------+--------+
2 rows in set (0.01 sec)
2、select depart_id,name, max(age) from emp group by depart_id;

对部门进行分组, 求出每个部门年龄最大的那个人

mysql> select depart_id,name, max(age) from emp group by depart_id;
+-----------+--------+----------+
| depart_id | name   | max(age) |
+-----------+--------+----------+
|         1 | egon   |       81 |
|         2 | 歪歪   |       48 |
|         3 | 张野   |       28 |
+-----------+--------+----------+
3 rows in set (0.01 sec)
3、min : 求最小的;
4、sum : 求和; select depart_id, sum(age) from emp group by depart_id;
mysql> select depart_id, sum(age) from emp group by depart_id;
+-----------+----------+
| depart_id | sum(age) |
+-----------+----------+
|         1 |      362 |
|         2 |      150 |
|         3 |      100 |
+-----------+----------+
3 rows in set (0.01 sec)
5、count : 计数; select depart_id,count(depart_id) from emp group by depart_id;
mysql> select depart_id,count(depart_id) from emp group by depart_id;
+-----------+------------------+
| depart_id | count(depart_id) |
+-----------+------------------+
|         1 |                8 |
|         2 |                5 |
|         3 |                5 |
+-----------+------------------+
3 rows in set (0.00 sec)
6、avg : 平均数; select depart_id, avg(age) from emp group by depart_id;
mysql> select depart_id, avg(age) from emp group by depart_id;
+-----------+----------+
| depart_id | avg(age) |
+-----------+----------+
|         1 |  45.2500 |
|         2 |  30.0000 |
|         3 |  20.0000 |
+-----------+----------+
3 rows in set (0.00 sec)

having:

having用于对group by之后的数据进行进一步的筛选

mysql> select depart_id, avg(age) from emp group by depart_id having avg(age)>35;
+-----------+----------+
| depart_id | avg(age) |
+-----------+----------+
|         1 |  45.2500 |
+-----------+----------+
1 row in set (0.01 sec)

order by: order by 字段名 asc(升序)/desc(降序)

对多个字段进行排序:

age asc, depart_id desc; 表示先对age进行降序,再把age相等的行按部门号进行升序排列

mysql> select * from emp order by age asc, depart_id desc;
+----+------------+--------+-----+------------+-----------------------------------------+--------------+------------+--------+-----------+
| id | name       | gender | age | hire_date  | post                                    | post_comment | salary     | office | depart_id |
+----+------------+--------+-----+------------+-----------------------------------------+--------------+------------+--------+-----------+
| 18 | 程咬铁     | female |  18 | 2014-05-12 | operation                               | NULL         |   17000.00 |    403 |         3 |
| 17 | 程咬铜     | male   |  18 | 2015-04-11 | operation                               | NULL         |   18000.00 |    403 |         3 |
| 16 | 程咬银     | female |  18 | 2013-03-11 | operation                               | NULL         |   19000.00 |    403 |         3 |
| 15 | 程咬金     | male   |  18 | 1997-03-12 | operation                               | NULL         |   20000.00 |    403 |         3 |
| 12 | 星星       | female |  18 | 2016-05-13 | sale                                    | NULL         |    3000.29 |    402 |         2 |
| 11 | 丁丁       | female |  18 | 2011-03-12 | sale                                    | NULL         |    1000.37 |    402 |         2 |
|  1 | egon       | male   |  18 | 2017-03-01 | 老男孩驻沙河办事处外交大使              | NULL         |    7300.33 |    401 |         1 |
|  7 | jinxin     | male   |  18 | 1900-03-01 | teacher                                 | NULL         |   30000.00 |    401 |         1 |
|  6 | jingliyang | female |  18 | 2011-02-11 | teacher                                 | NULL         |    9000.00 |    401 |         1 |
| 14 | 张野       | male   |  28 | 2016-03-11 | operation                               | NULL         |   10000.13 |    403 |         3 |
| 13 | 格格       | female |  28 | 2017-01-27 | sale                                    | NULL         |    4000.33 |    402 |         2 |
|  5 | liwenzhou  | male   |  28 | 2012-11-01 | teacher                                 | NULL         |    2100.00 |    401 |         1 |
| 10 | 丫丫       | female |  38 | 2010-11-01 | sale                                    | NULL         |    2000.35 |    402 |         2 |
|  9 | 歪歪       | female |  48 | 2015-03-11 | sale                                    | NULL         |    3000.13 |    402 |         2 |
|  8 | 成龙       | male   |  48 | 2010-11-11 | teacher                                 | NULL         |   10000.00 |    401 |         1 |
|  4 | yuanhao    | male   |  73 | 2014-07-01 | teacher                                 | NULL         |    3500.00 |    401 |         1 |
|  2 | alex       | male   |  78 | 2015-03-02 | teacher                                 | NULL         | 1000000.31 |    401 |         1 |
|  3 | wupeiqi    | male   |  81 | 2013-03-05 | teacher                                 | NULL         |    8300.00 |    401 |         1 |
+----+------------+--------+-----+------------+-----------------------------------------+--------------+------------+--------+-----------+
18 rows in set (0.01 sec)

select * from emp order by depart_id asc, age desc;

mysql> select * from emp order by depart_id asc, age desc;
+----+------------+--------+-----+------------+-----------------------------------------+--------------+------------+--------+-----------+
| id | name       | gender | age | hire_date  | post                                    | post_comment | salary     | office | depart_id |
+----+------------+--------+-----+------------+-----------------------------------------+--------------+------------+--------+-----------+
|  3 | wupeiqi    | male   |  81 | 2013-03-05 | teacher                                 | NULL         |    8300.00 |    401 |         1 |
|  2 | alex       | male   |  78 | 2015-03-02 | teacher                                 | NULL         | 1000000.31 |    401 |         1 |
|  4 | yuanhao    | male   |  73 | 2014-07-01 | teacher                                 | NULL         |    3500.00 |    401 |         1 |
|  8 | 成龙       | male   |  48 | 2010-11-11 | teacher                                 | NULL         |   10000.00 |    401 |         1 |
|  5 | liwenzhou  | male   |  28 | 2012-11-01 | teacher                                 | NULL         |    2100.00 |    401 |         1 |
|  1 | egon       | male   |  18 | 2017-03-01 | 老男孩驻沙河办事处外交大使              | NULL         |    7300.33 |    401 |         1 |
|  6 | jingliyang | female |  18 | 2011-02-11 | teacher                                 | NULL         |    9000.00 |    401 |         1 |
|  7 | jinxin     | male   |  18 | 1900-03-01 | teacher                                 | NULL         |   30000.00 |    401 |         1 |
|  9 | 歪歪       | female |  48 | 2015-03-11 | sale                                    | NULL         |    3000.13 |    402 |         2 |
| 10 | 丫丫       | female |  38 | 2010-11-01 | sale                                    | NULL         |    2000.35 |    402 |         2 |
| 13 | 格格       | female |  28 | 2017-01-27 | sale                                    | NULL         |    4000.33 |    402 |         2 |
| 11 | 丁丁       | female |  18 | 2011-03-12 | sale                                    | NULL         |    1000.37 |    402 |         2 |
| 12 | 星星       | female |  18 | 2016-05-13 | sale                                    | NULL         |    3000.29 |    402 |         2 |
| 14 | 张野       | male   |  28 | 2016-03-11 | operation                               | NULL         |   10000.13 |    403 |         3 |
| 15 | 程咬金     | male   |  18 | 1997-03-12 | operation                               | NULL         |   20000.00 |    403 |         3 |
| 16 | 程咬银     | female |  18 | 2013-03-11 | operation                               | NULL         |   19000.00 |    403 |         3 |
| 17 | 程咬铜     | male   |  18 | 2015-04-11 | operation                               | NULL         |   18000.00 |    403 |         3 |
| 18 | 程咬铁     | female |  18 | 2014-05-12 | operation                               | NULL         |   17000.00 |    403 |         3 |
+----+------------+--------+-----+------------+-----------------------------------------+--------------+------------+--------+-----------+
18 rows in set (0.00 sec)

limit 分页: limit offset, size

offset 表示 行数据索引; size 表示取多少条数据

从第offset行开始,取size行数据。

mysql> select * from emp limit 0,10;
+----+------------+--------+-----+------------+-----------------------------------------+--------------+------------+--------+-----------+
| id | name       | gender | age | hire_date  | post                                    | post_comment | salary     | office | depart_id |
+----+------------+--------+-----+------------+-----------------------------------------+--------------+------------+--------+-----------+
|  1 | egon       | male   |  18 | 2017-03-01 | 老男孩驻沙河办事处外交大使              | NULL         |    7300.33 |    401 |         1 |
|  2 | alex       | male   |  78 | 2015-03-02 | teacher                                 | NULL         | 1000000.31 |    401 |         1 |
|  3 | wupeiqi    | male   |  81 | 2013-03-05 | teacher                                 | NULL         |    8300.00 |    401 |         1 |
|  4 | yuanhao    | male   |  73 | 2014-07-01 | teacher                                 | NULL         |    3500.00 |    401 |         1 |
|  5 | liwenzhou  | male   |  28 | 2012-11-01 | teacher                                 | NULL         |    2100.00 |    401 |         1 |
|  6 | jingliyang | female |  18 | 2011-02-11 | teacher                                 | NULL         |    9000.00 |    401 |         1 |
|  7 | jinxin     | male   |  18 | 1900-03-01 | teacher                                 | NULL         |   30000.00 |    401 |         1 |
|  8 | 成龙       | male   |  48 | 2010-11-11 | teacher                                 | NULL         |   10000.00 |    401 |         1 |
|  9 | 歪歪       | female |  48 | 2015-03-11 | sale                                    | NULL         |    3000.13 |    402 |         2 |
| 10 | 丫丫       | female |  38 | 2010-11-01 | sale                                    | NULL         |    2000.35 |    402 |         2 |
+----+------------+--------+-----+------------+-----------------------------------------+--------------+------------+--------+-----------+
10 rows in set (0.00 sec)

从第6行开始取10行:

mysql> select * from emp limit 6,10;
+----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
| id | name      | gender | age | hire_date  | post      | post_comment | salary   | office | depart_id |
+----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
|  7 | jinxin    | male   |  18 | 1900-03-01 | teacher   | NULL         | 30000.00 |    401 |         1 |
|  8 | 成龙      | male   |  48 | 2010-11-11 | teacher   | NULL         | 10000.00 |    401 |         1 |
|  9 | 歪歪      | female |  48 | 2015-03-11 | sale      | NULL         |  3000.13 |    402 |         2 |
| 10 | 丫丫      | female |  38 | 2010-11-01 | sale      | NULL         |  2000.35 |    402 |         2 |
| 11 | 丁丁      | female |  18 | 2011-03-12 | sale      | NULL         |  1000.37 |    402 |         2 |
| 12 | 星星      | female |  18 | 2016-05-13 | sale      | NULL         |  3000.29 |    402 |         2 |
| 13 | 格格      | female |  28 | 2017-01-27 | sale      | NULL         |  4000.33 |    402 |         2 |
| 14 | 张野      | male   |  28 | 2016-03-11 | operation | NULL         | 10000.13 |    403 |         3 |
| 15 | 程咬金    | male   |  18 | 1997-03-12 | operation | NULL         | 20000.00 |    403 |         3 |
| 16 | 程咬银    | female |  18 | 2013-03-11 | operation | NULL         | 19000.00 |    403 |         3 |
+----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
10 rows in set (0.00 sec)

多表操作

外键: 占用空间少,方便修改数据

一对多:

语法: constraint 外键名 foreign key (被约束的字段) references 约束的表(约束的字段)

mysql> create table dep(
    -> id int auto_increment primary key,
    -> name varchar(32) not null default ''
    -> )charset=utf8;

mysql> insert into dep (name) values ('研发部'),('运维部'),('前台部'),('小卖部');

mysql> create table userinfo (
    -> id int auto_increment primary key,
    -> name varchar(32) not null default '',
    -> depart_id int not null default 1,
    ->
    -> constraint fk_user_depart foreign key (depart_id) references dep(id)
    -> )charset utf8;

mysql> insert into userinfo (name, depart_id) values ('allen a',1);
mysql> insert into userinfo (name, depart_id) values ('allen b',2);
mysql> insert into userinfo (name, depart_id) values ('allen c',3);
mysql> insert into userinfo (name, depart_id) values ('allen d',4);
mysql> insert into userinfo (name, depart_id) values ('allen e',1);
mysql> insert into userinfo (name, depart_id) values ('allen f',2);
mysql> insert into userinfo (name, depart_id) values ('allen g',3);
以上7行符合外键要求,所以能插入不报错,但下边一行插入时会报错
mysql> insert into userinfo (name, depart_id) values ('allen h',5);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql> insert into userinfo (name, depart_id) values ('allen h',5)' at line 1

多对多:

创建男生表

mysql> create table boy(
    -> id int auto_increment primary key,
    -> bname varchar(32) not null default ''
    -> )charset=utf8;

insert into boy (bname) values ('xiaoming'),('xiaogang'),('xiaoqiang');

创建女生表

mysql> create table girl(
    -> id int auto_increment primary key,
    -> gname varchar(32) not null default ''
    -> )charset=utf8;

mysql> insert into girl (gname) values ('xiaohong'),('xiaoli'),('xiaojiao');

创建关联表

mysql> create table b2g(
    -> id int auto_increment primary key,
    -> bid int not null default 1,
    -> gid int not null default 0,
    ->
    -> constraint fk_b2g_boy foreign key (bid) references boy(id),
    -> constraint fk_b2g_girl foreign key (gid) references girl(id)
    -> )charset utf8;

mysql> insert into b2g (bid, gid) values (1,1),(1,2),(2,3),(3,3),(2,2);

用到 left jion :

mysql> select * from boy left join b2g on boy.id=b2g.bid left join girl on girl.id=b2g.gid;
+----+-----------+------+------+------+------+----------+
| id | bname     | id   | bid  | gid  | id   | gname    |
+----+-----------+------+------+------+------+----------+
|  1 | xiaoming  |    1 |    1 |    1 |    1 | xiaohong |
|  1 | xiaoming  |    2 |    1 |    2 |    2 | xiaoli   |
|  2 | xiaogang  |    5 |    2 |    2 |    2 | xiaoli   |
|  2 | xiaogang  |    3 |    2 |    3 |    3 | xiaojiao |
|  3 | xiaoqiang |    4 |    3 |    3 |    3 | xiaojiao |
+----+-----------+------+------+------+------+----------+
5 rows in set (0.01 sec)
mysql> select bname, gname from boy left join b2g on boy.id=b2g.bid left join girl on girl.id=b2g.gid;
+-----------+----------+
| bname     | gname    |
+-----------+----------+
| xiaoming  | xiaohong |
| xiaoming  | xiaoli   |
| xiaogang  | xiaoli   |
| xiaogang  | xiaojiao |
| xiaoqiang | xiaojiao |
+-----------+----------+
5 rows in set (0.00 sec)

一对一:

创建员工信息表

mysql> create table user(
    -> id int auto_increment primary key,
    -> name varchar(32) not null default ''
    -> )charset=utf8;

mysql> insert into user (name) values ('xiaoming'),('xiaogang'),('xiaoqiang');

mysql> select * from user;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | xiaoming  |
|  2 | xiaogang  |
|  3 | xiaoqiang |
+----+-----------+
3 rows in set (0.00 sec)

创建员工工资表

mysql> create table priv(
    -> id int auto_increment primary key,
    -> salary int not null default 0,
    -> uid int not null default 1,
    ->
    -> constraint fk_priv_user foreign key (uid) references user(id),
    -> unique(uid)
    -> )charset=utf8;

mysql> insert into priv (salary, uid) values (2000, 1),(2500,2),(3000,3);

mysql> select * from priv;
+----+--------+-----+
| id | salary | uid |
+----+--------+-----+
|  1 |   2000 |   1 |
|  2 |   2500 |   2 |
|  3 |   3000 |   3 |
+----+--------+-----+
3 rows in set (0.00 sec)

多表联查:

left join ...on... :

mysql> select userinfo.name as uname, dep.name as dname from userinfo left join dep on depart_id=dep.id;
+---------+-----------+
| uname   | dname     |
+---------+-----------+
| allen a | 研发部    |
| allen e | 研发部    |
| allen b | 运维部    |
| allen f | 运维部    |
| allen c | 前台部    |
| allen g | 前台部    |
| allen d | 小卖部    |
+---------+-----------+
7 rows in set (0.01 sec)

mysql> select userinfo.name as uname, dep.name as dname from userinfo left join dep on depart_id=dep.id;
+---------+-----------+
| uname   | dname     |
+---------+-----------+
| allen a | 研发部    |
| allen e | 研发部    |
| allen b | 运维部    |
| allen f | 运维部    |
| allen c | 前台部    |
| allen g | 前台部    |
| allen d | 小卖部    |
+---------+-----------+
7 rows in set (0.01 sec)

right join ...on...

inner join

原文地址:https://www.cnblogs.com/allenchen168/p/11768705.html

时间: 2024-11-08 10:25:07

MySQL 基础之 单表、多表联查的相关文章

mysql基础之创建数据库和表

假设你已拥有创建和修改服务器上数据库所必需的权限,那么我们来看一下如何创建数据库以及数据库中的表.在本章的示例中,我们将为一个虚拟的书店建立一个数据库: CREATE DATABASE bookstore; 通过这条简单的SQL语句,我们已经创建了名为bookstore的数据库.另外,MySQL语句以及子句中的保留字对大小写不敏感.数据库与表名对大小写是否敏感取决于你所用的操作系统,比如在Linux系统上对大小写是敏感的,而Window系统对大小写不敏感.按照通常的习惯,在SQL说明文档中保留字

MYSQL基础笔记(三)-表操作基础

数据表的操作 表与字段是密不可分的. 新增数据表 1 Create table [if not exists] 表名( 2 字段名 数据类型, 3 字段名 数据类型, 4 字段n 数据类型 --最后一行不需要加逗号 5 )[表选项]; If not exists:如果表名不存在,那么就创建,否则不执行创建代码,实现检查功能. 表选项:控制表的表现 1.字符集:charset/character 具体字符集:--保证表中数据存储的字符集. 2.校对集:collate 具体校对集: 3.存储引擎:e

基于MySql数据库的单表与多表联合查询

这里以学生 班级 身份证 以及课程为例 1,启动MySql数据库  开启服务 2.1.0新建一张班级表 备注:CHARSET = UTF8 (指定编码格式为utf8 防止中文乱码) /*班级表*/ CREATE TABLE CLASS_INFO( C_ID INT PRIMARY KEY, CLASS_NAME VARCHAR(20) not NULL )CHARSET = UTF8; 运行效果: 新建成功 2.1.1依次建好学生表(学生表有一个指向班级表的主键  以便做关联查询) /*学生表*

MySQL基础学习之数据表

查看数据表 SHOW TABLE; 查看数据表详细结构 SHOW CREATE TABLE 表名\G; 创建数据表 CREATE TABLE 表名(数据名 类型,数据名1  类型2); CREATE TABLE department ( d_id INT(10) , d_name VARCHAR(20) , function VARCHAR(20) , address VARCHAR(30) ); 删除数据表 DROP TABLE 表名; 修改数据表 修改数据表名        ALTER TA

mysql简单的单表查询详解

mysql简单的单表查询详解 MySQL的查询操作: 单表查询:简单查询 多表查询:连续查询 联合查询: 选择和投影: 投影:挑选要显示的字段 选择:挑选符合条件的行 投影:SELECT 字段1, 字段2, ... FROM tb_name;  SELECT * FROM tb_name; 选择:SELECT 字段1, ... FROM tb_name WHERE 子句; 布尔条件表达式 mysql> CREATE TABLE students (SID INT UNSIGNED AUTO_IN

mysql基础之对库表操作

原文:mysql基础之对库表操作 查看一下所有的库,怎么办? Mysql>Show databases; 选库语句: Use 库名 创建一个数据库: create database 数据库名 [charset 字符集] 删除一个数据库: drop database 数据库名; 把数据库改改名? Mysql中,表/列可以改名,database不能改名. phpMyAdmin似乎有这功能? 他是建新库,把所有表复制到新库,再删旧库完成的. 当选了库之后,我们面对的是表 查看库下面的所有表: show

JavaScript基础笔记(十)表单脚本

表单脚本 一.表单基础知识 JavaScript中表单对应的是HTMLFormElement类型,该类型继承自HTMLElement类型. 通过document.forms可以获得所有表单元素,通过数值索引和name特性可以获得其中特定的表单. 一)提交表单 单击提交按钮或者图像按钮就可以提交表单. 三种方式: <!--通用提交按钮--> <input type='submit' value='submit value'> <!--自定义提交按钮--> <butt

MySQL数据库:SQL语句基础、库操作、表操作、数据类型、约束条件、表之间的关系

数据库相关概念: 1. 数据库服务器:运行数据库管理软件的计算机 2. 数据库管理软件:MySQL.Oracle.db2.slqserver 3. 库:文件夹,用来组织文件/表 4. 表:文件(类似于excel),用来存放多行内容/多条记录 5. 记录:事物一系列典型的特征 6. 数据:描述事物特征的符号 MySQL数据库就是一个套接字软件,用来管理其他机器上的数据文件 MySQL介绍: MySQL是一个关系型数据库管理系统:就是一个基于socket编写的C/S架构胡软件 客户端软件 mysql

MySQL学习9 - 单表查询

一.单表查询的语法 二.关键字的执行优先级(重点) 三.单表查询示例 1.where约束 2.group by分组查询 3.聚合函数 4.HAVING过滤 5.order by查询排序 6.limit 限制查询的记录数 一.单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 二.关键字的执行优先级(重点) 重点中的重点:关键字的执行优先级 from where