练习——MySQL 查询

基础题数据准备先创建student和score表,添加基本数据,用于查询演练创建student表SQL代码如下create table student(id int(10) not null unique primary key,name varchar(20) not null,gender varchar(4),birth year,department varchar(20),address varchar(50));创建score表SQL代码如下:create tab
摘要由CSDN通过智能技术生成

基础题

数据准备
先创建student和score表,添加基本数据,用于查询演练
创建student表SQL代码如下

create table student(
id int(10) not null unique primary key,
name varchar(20) not null,
gender varchar(4),
birth year,
department varchar(20),
address varchar(50)
);

创建score表SQL代码如下:

create table score(
id int(10) not null unique primary key auto_increment,
stu_id int(10) not null,
c_name varchar(20),
grade int(10)
);

向student表插入记录的insert语句如下:

insert into student values
( 901,‘张老大’,‘男’,1985,‘计算机系’,‘北京市海淀区’),
( 902,‘张老二’, ‘男’,1986,‘中文系’, ‘北京市昌平区’),
( 903,‘张三’, ‘女’,1990,‘中文系’, ‘湖南省永州市’),
( 904,‘李四’, ‘男’,1990,‘英语系’, ‘辽宁省阜新市’),
( 905,‘王五’, ‘女’,1991,‘英语系’, ‘福建省厦门市’),
( 906,‘王六’, ‘男’,1988,‘计算机系’, ‘湖南省衡阳市’);

向score表插入记录的insert语句如下:

insert into score values
(NULL,901, ‘计算机’,98),
(NULL,901, ‘英语’, 80),
(NULL,902, ‘计算机’,65),
(NULL,902, ‘中文’,88),
(NULL,903, ‘中文’,95),
(NULL,904, ‘计算机’,70),
(NULL,904, ‘英语’,92),
(NULL,905, ‘英语’,94),
(NULL,906, ‘计算机’,90),
(NULL,906, ‘英语’,85);

mysql> select * from student;
+-----+-----------+--------+-------+--------------+--------------------+
| id  | name      | gender | birth | department   | address            |
+-----+-----------+--------+-------+--------------+--------------------+
| 901 | 张老大    ||  1985 | 计算机系     | 北京市海淀区       |
| 902 | 张老二    ||  1986 | 中文系       | 北京市昌平区       |
| 903 | 张三      ||  1990 | 中文系       | 湖南省永州市       |
| 904 | 李四      ||  1990 | 英语系       | 辽宁省阜新市       |
| 905 | 王五      ||  1991 | 英语系       | 福建省厦门市       |
| 906 | 王六      ||  1988 | 计算机系     | 湖南省衡阳市       |
+-----+-----------+--------+-------+--------------+--------------------+
6 rows in set (0.00 sec)

mysql> select * from score;
+----+--------+-----------+-------+
| id | stu_id | c_name    | grade |
+----+--------+-----------+-------+
|  1 |    901 | 计算机    |    98 |
|  2 |    901 | 英语      |    80 |
|  3 |    902 | 计算机    |    65 |
|  4 |    902 | 中文      |    88 |
|  5 |    903 | 中文      |    95 |
|  6 |    904 | 计算机    |    70 |
|  7 |    904 | 英语      |    92 |
|  8 |    905 | 英语      |    94 |
|  9 |    906 | 计算机    |    90 |
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值