mysql中怎么向视图中添加原表没有的字段呢?
问题描述:
1.在mydb数据库中创建student数据表,表中有id、name(学生姓名)、math(数学成绩)、chinese(语文成绩)和english(英语成绩) 字段。然后创建视图view_score,视图中包含math、chinese、english和total(总分数)字段。
答
/*代码如下*/
/*创建视图view_score*/
create view view_score AS
select math,chinese,english,math+chinese+english total from student;
答
是不是要加total分数这个字段?可以通过as 关键字加别名即可
select math,chinese,english,sum(math+chinese+english) as total from student GROUP BY math,chinese,english