练习07_20200817(实现行转列)

1、现在有如下流程:A->B->C->D->E->F,要求根据输入的参数从制定的流程执行下去

process = ['A', 'B', 'C', 'D', 'E', 'F']

print("流程系统".center(50, '*'))
print("现有如下流程:A->B->C->D->E->F")

args = input("请输入当前所在环节:")
if args in process:
    index = process.index(args)
    for i in range(len(process) - index - 1):
        print("下一环节为{}".format(process[index + 1]))
        index = index + 1
    print("流程结束")

else:
    print("当前流程不包含{},请重新输入!".format(args))

练习07_20200817(实现行转列)_第1张图片

2、数据库题目:数据库记录行转列
现有数据库记录如下:

练习07_20200817(实现行转列)_第2张图片

编写 SQL语句,查询结果按照如下要求展示

练习07_20200817(实现行转列)_第3张图片

创建表
CREATE TABLE grade (
Name VARCHAR(50),
Subject VARCHAR(50),
Score INT
)CHARACTER SET utf8  COLLATE utf8_general_ci 
插入数据
INSERT INTO grade VALUES('Nick','语文','80'),
('Nick','数学','90'),
('Nick','英语','70'),
('Nick','生物','85'),
('Kent','语文','80'),
('Kent','数学','90'),
('Kent','英语','70'),
('Kent','生物','85')
行列转换查询
select Name,  
  sum(IF(Subject = '语文', score,null)) as '语文',  
  sum(IF(Subject = '数学', score,null)) as '数学',  
  sum(IF(Subject = '英语', score,null)) as '英语',
  sum(IF(Subject = '生物', score,null)) as '生物'
from grade 
group by Name

练习07_20200817(实现行转列)_第4张图片

参考链接:https://blog.csdn.net/lilong329329/article/details/81664451

https://www.cnblogs.com/tiny-me/p/11774735.html

 

 

 

 

 

你可能感兴趣的:(自动化_python学习,python学习,数据库,mysql,python,sql)