您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
今天小编给大家分享一下mysql学生表怎么创建的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。
题目:
create table student (
id varchar(20),
name varchar(20),
gender char(1),
birth varchar(20),
department varchar(20),
address varchar(20)
) charset = utf8;
insert into student values
("201901","张大佬","男","1985","计算机系","北京市海淀区"),
("201902","郭大侠","男","1986","中文系","北京市昌平区"),
("201903","张三","女","1990","中文系","湖南省永州市"),
("201904","李四","男","1990","英语系","辽宁市阜新市"),
("201905","王五","女","1991","英语系","福建省厦门市"),
("201906","王六","男","1988","计算机系","湖南省衡阳市");
select
department 院系,
case gender when "男" then 1 else 0 end 男,
case gender when "女" then 1 else 0 end 女
from student;
select
院系,
sum(男) 男,
sum(女) 女,
sum(男) + sum(女) as 总计
from
(
select department 院系,
case gender when "男" then 1 else 0 end 男,
case gender when "女" then 1 else 0 end 女
from student
) a
group by 院系;
以上就是“mysql学生表怎么创建”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。