是否可以在mysql视图中创建自动增量id列? [英] Is it possible to create auto increment id column in mysql view?
本文介绍了是否可以在mysql视图中创建自动增量id列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在MySql中创建了一个视图.但是现在我的要求是在该视图中创建一个ID列,该列应该是自动递增的.
I have created a view in MySql. But now my requirement is to create an Id column in that view which should be auto increment.
我当前的视图是:-
CREATE VIEW pending_assign_report_view AS
select cg.group_name,c.client_name, wt.work_type,p.Minor_worktype, ay.year,aev.emp_name,ep.Date_assigned_on
from employee_project ep,active_employee_view aev, project p, client_group cg, client c,work_type wt,assessment_year ay
where ep.task_status_id=1 and ep.username=aev.username and ep.project_id=p.project_id and p.Year_id=ay.Year_id
and p.Client_group_id=cg.client_group_id and p.Client_id=c.Client_id and p.Work_type_id=wt.Work_type_id
order by cg.group_name,c.client_name, aev.emp_name;
现在,我希望将Id列作为第一列,该列本质上应为auto_increment.我应该怎么做? 预先感谢.
Now I want Id column as first column which should be auto_increment in nature. How should I do this? Thanks in advance.
推荐答案
您可以在SELECT中使用类似的代码来模拟它:
You can simulate it with something like this in your SELECT:
SELECT @rownum:=@rownum+1 AS rownum, dummy.*
FROM (SELECT @rownum:=0) r, dummy;
这篇关于是否可以在mysql视图中创建自动增量id列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文