想实类似于在创建视图时增加一个自增的字段,应如实现,请给出具体的代码附:
MSSql 有这样实现的,但是必须新建表,能不能不新建表也可以,谢谢
drop table #tab;
select id=identity(int,1,1),userName,crtdate into #tab from dy.test;
select * from #tab;

解决方案 »

  1.   

    完全没必要  在用视图得时候再做自增id是完全可以的set @t=1;
    select @t:=@t+1,col1 from view_tb;
    另外sqlserver2005也没必要插临时表,有函数可以直接生成自增列
    select  row_number() over(order by col) as num,col1 from tb;
      

  2.   

    set @t=1;
    select @t:=@t+1,col1 from view_tb order by xxx;
      

  3.   

    在MSSQL 下如下运行通过
    create view view_test as
    select row_number()over(order by userName) as idt,userName  from dy.test group by userName
    select * from view_test但是 mysql 要如何实现类似的功能
      

  4.   

    MYSQL 创建视图不能有函数和变量,就问要怎么实现,请名位大侠多多指教!!
      

  5.   


    mysql> create temporary table if not exists tb_temp_tb1(id int AUTO_INCREMENT pr
    imary key,intime datetime,tid int,txt varchar(10)) select intime,tid,txt from tb
    1;
    Query OK, 3 rows affected (0.08 sec)
    Records: 3  Duplicates: 0  Warnings: 0mysql> select * from tb_temp_tb1;
    +----+---------------------+------+------+
    | id | intime              | tid  | txt  |
    +----+---------------------+------+------+
    |  1 | 2011-04-11 15:00:00 |    1 | test |
    |  2 | 2011-04-11 15:00:00 |    2 | test |
    |  3 | 2011-04-11 15:00:00 |    3 | test |
    +----+---------------------+------+------+
    3 rows in set (0.00 sec)mysql> select * from tb1;
    +---------------------+------+------+
    | intime              | tid  | txt  |
    +---------------------+------+------+
    | 2011-04-11 15:00:00 | 1    | test |
    | 2011-04-11 15:00:00 | 2    | test |
    | 2011-04-11 15:00:00 | 3    | test |