想实类似于在创建视图时增加一个自增的字段,应如实现,请给出具体的代码附:
MSSql 有这样实现的,但是必须新建表,能不能不新建表也可以,谢谢
drop table #tab;
select id=identity(int,1,1),userName,crtdate into #tab from dy.test;
select * from #tab;
MSSql 有这样实现的,但是必须新建表,能不能不新建表也可以,谢谢
drop table #tab;
select id=identity(int,1,1),userName,crtdate into #tab from dy.test;
select * from #tab;
解决方案 »
- 求mysql select语句的执行顺序
- 如何把SQL2000存储过程改为Mysql支持的存储过程?
- 两个数据库如何相连?(请高人指点)
- MariaDB 在 Windows 下 noinstall 版本的安装和使用
- sql优化,这个sql还有优化的可能吗?
- mysql查询结果如果可以去掉最新的两条纪录
- 如何才能删除数据表中满足条件的后n条记录
- 怎么找到指定路径下的数据库?
- 在LINUX下配置MYSQL的问题,请高手帮忙~~
- cast(int值 as datetime)或convert(int值 , datetime)总是不能成功,插入数据总是为NULL
- 数据表中有timestamp,如何查询出表中所有时间间隔为1分钟的记录
- 这个游标怎么没结果呢?
select @t:=@t+1,col1 from view_tb;
另外sqlserver2005也没必要插临时表,有函数可以直接生成自增列
select row_number() over(order by col) as num,col1 from tb;
select @t:=@t+1,col1 from view_tb order by xxx;
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 要如何实现类似的功能
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 |