mysql查询数据导入_MySQL数据导入导出及查询

第一个表、

Enter password: ****

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 6

Server version: 5.6.13-enterprise-commercial-advanced MySQL Enterprise Server -

Advanced Edition (Commercial)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| csdn               |

| mysql              |

| performance_schema |

| test               |

+--------------------+

5 rows in set (0.00 sec)

mysql> use test;

Database changed

mysql> drop table if exists student;

Query OK, 0 rows affected (0.31 sec)

mysql> drop table if exists class;

Query OK, 0 rows affected (0.11 sec)

mysql> create table class(专业varchar(30),班级varchar(20),姓名varchar(20),性

别 varchar(10),座号int);

Query OK, 0 rows affected (0.70 sec)

mysql> desc class;

+--------+-------------+------+-----+---------+-------+

| Field  | Type        | Null | Key | Default | Extra |

+--------+-------------+------+-----+---------+-------+

| 专业| varchar(30) | YES  |     | NULL    |       |

| 班级| varchar(20) | YES  |     | NULL    |       |

| 姓名| varchar(20) | YES  |     | NULL    |       |

| 性别| varchar(10) | YES  |     | NULL    |       |

| 座号| int(11)     | YES  |     | NULL    |       |

+--------+-------------+------+-----+---------+-------+

5 rows in set (0.01 sec)

mysql> insert into class values('计算机网络','1班','张三','男',8);

Query OK, 1 row affected (0.09 sec)

mysql> insert into class values('软件工程','2班','李四','男',12);

Query OK, 1 row affected (0.09 sec)

mysql> insert into class values('计算机维护','1班','王五','男',9);

Query OK, 1 row affected (0.08 sec)

mysql> insert into class values('计算机网络','2班','LILY','女',15);

Query OK, 1 row affected (0.08 sec)

mysql> insert into class values('软件工程','1班','小强','男',20);

Query OK, 1 row affected (0.08 sec)

mysql> insert into class values('计算机维护','1班','CoCo','女',18);

Query OK, 1 row affected (0.09 sec)

mysql> select * from class;

+-----------------+--------+--------+--------+--------+

| 专业|班级|姓名|性别|座号|

+-----------------+--------+--------+--------+--------+

| 计算机网络| 1班|张三|男|      8 |

| 软件工程| 2班|李四|男|     12 |

| 计算机维护| 1班|王五|男|      9 |

| 计算机网络| 2班| LILY   |女|     15 |

| 软件工程| 1班|小强|男|     20 |

| 计算机维护| 1班| CoCo   |女|     18 |

+-----------------+--------+--------+--------+--------+

6 rows in set (0.00 sec)

第二个表、

mysql> create table score(姓名varchar(20),英语int,数学int,语文int);

Query OK, 0 rows affected (0.49 sec)

mysql> desc score;

+--------+-------------+------+-----+---------+-------+

| Field  | Type        | Null | Key | Default | Extra |

+--------+-------------+------+-----+---------+-------+

| 姓名| varchar(20) | YES  |     | NULL    |       |

| 英语| int(11)     | YES  |     | NULL    |       |

| 数学| int(11)     | YES  |     | NULL    |       |

| 语文| int(11)     | YES  |     | NULL    |       |

+--------+-------------+------+-----+---------+-------+

4 rows in set (0.01 sec)

mysql> insert into score values('张三',65,75,98);

Query OK, 1 row affected (0.09 sec)

mysql> insert into score values('李四',87,45,86);

Query OK, 1 row affected (0.04 sec)

mysql> insert into score values('王五'98,85,65);

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 '98,85

,65)' at line 1

mysql> insert into score values('王五',98,85,65);

Query OK, 1 row affected (0.08 sec)

mysql> insert into score values('LILY',75,86,87);

Query OK, 1 row affected (0.08 sec)

mysql> insert into score values('小强',85,60,58);

Query OK, 1 row affected (0.08 sec)

mysql> insert into score values('CoCo',96,87,70);

Query OK, 1 row affected (0.09 sec)

mysql> select * from score;

+--------+--------+--------+--------+

| 姓名|英语|数学|语文|

+--------+--------+--------+--------+

| 张三|     65 |     75 |     98 |

| 李四|     87 |     45 |     86 |

| 王五|     98 |     85 |     65 |

| LILY   |     75 |     86 |     87 |

| 小强|     85 |     60 |     58 |

| CoCo   |     96 |     87 |     70 |

+--------+--------+--------+--------+

6 rows in set (0.00 sec)

第三个表、

mysql> create table record(姓名varchar(20),记录varchar(20));

Query OK, 0 rows affected (0.67 sec)

mysql> desc record;

+--------+-------------+------+-----+---------+-------+

| Field  | Type        | Null | Key | Default | Extra |

+--------+-------------+------+-----+---------+-------+

| 姓名| varchar(20) | YES  |     | NULL    |       |

| 记录| varchar(20) | YES  |     | NULL    |       |

+--------+-------------+------+-----+---------+-------+

2 rows in set (0.01 sec)

mysql> insert into record values('小强','迟到');

Query OK, 1 row affected (0.06 sec)

mysql> insert into record values('小强','事假');

Query OK, 1 row affected (0.09 sec)

mysql> insert into record values('李四','旷课');

Query OK, 1 row affected (0.11 sec)

mysql> insert into record values('李四','旷课');

Query OK, 1 row affected (0.08 sec)

mysql> insert into record values('李四','迟到');

Query OK, 1 row affected (0.10 sec)

mysql> insert into record values('CoCo','病假');

Query OK, 1 row affected (0.08 sec)

mysql> insert into record values('LILY','事假');

Query OK, 1 row affected (0.08 sec)

mysql> select * from record;

+--------+--------+

| 姓名|记录|

+--------+--------+

| 小强|迟到|

| 小强|事假|

| 李四|旷课|

| 李四|旷课|

| 李四|迟到|

| CoCo   | 病假|

| LILY   | 事假|

+--------+--------+

7 rows in set (0.00 sec)

1、用一条语句搜索出张三所在的班级及其坐号。

mysql> select 班级,座号from class where姓名like '张三';

+--------+--------+

| 班级|座号|

+--------+--------+

| 1班|      8 |

+--------+--------+

1 row in set (0.08 sec)

2、用一条语句搜索出计算机维护1班所有人的考勤记录。

mysql> select class.专业,class.班级,class.姓名,record.记录from class,record whe

re class.姓名=record.姓名and class.专业='计算机维护' and class.班级='1班';

+-----------------+--------+--------+--------+

| 专业|班级|姓名|记录|

+-----------------+--------+--------+--------+

| 计算机维护| 1班| CoCo   |病假|

+-----------------+--------+--------+--------+

1 row in set (0.07 sec)

3、用一条语句搜索有一科分数不及格而且有旷课的人的名单。

mysql> select distinct score.姓名,score.英语,score.数学,score.语文,record.记录f

rom score,record where score.姓名=record.姓名and( score.英语<=60 or score.数学<

=60 or score.语文<=60) and record.记录='旷课';

+--------+--------+--------+--------+--------+

| 姓名|英语|数学|语文|记录|

+--------+--------+--------+--------+--------+

| 李四|     87 |     45 |     86 |旷课|

+--------+--------+--------+--------+--------+

1 row in set (0.00 sec)

4、导出数据库保存为“csdn-0913.sql”

Microsoft Windows [版本6.1.7601]

版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>mysqldump -h localhost -u root -p test>d:\csdn-0913.sql

Enter password: ****

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值