mysql中列rownum_MySQL中模拟oracle中的rownum列

mysql> select @rn := @rn + 1 as rownum, emp_no, dept_no, from_date, to_date

-> from dept_emp, (select @rn := 0) a limit 20;

+--------+--------+---------+------------+------------+

| rownum | emp_no | dept_no | from_date | to_date |

+--------+--------+---------+------------+------------+

| 1 | 10001 | d005 | 1986-06-26 | 9999-01-01 |

| 2 | 10002 | d007 | 1996-08-03 | 9999-01-01 |

| 3 | 10003 | d004 | 1995-12-03 | 9999-01-01 |

| 4 | 10004 | d004 | 1986-12-01 | 9999-01-01 |

| 5 | 10005 | d003 | 1989-09-12 | 9999-01-01 |

| 6 | 10006 | d005 | 1990-08-05 | 9999-01-01 |

| 7 | 10007 | d008 | 1989-02-10 | 9999-01-01 |

| 8 | 10008 | d005 | 1998-03-11 | 2000-07-31 |

| 9 | 10009 | d006 | 1985-02-18 | 9999-01-01 |

| 10 | 10010 | d004 | 1996-11-24 | 2000-06-26 |

| 11 | 10010 | d006 | 2000-06-26 | 9999-01-01 |

| 12 | 10011 | d009 | 1990-01-22 | 1996-11-09 |

| 13 | 10012 | d005 | 1992-12-18 | 9999-01-01 |

| 14 | 10013 | d003 | 1985-10-20 | 9999-01-01 |

| 15 | 10014 | d005 | 1993-12-29 | 9999-01-01 |

| 16 | 10015 | d008 | 1992-09-19 | 1993-08-22 |

| 17 | 10016 | d007 | 1998-02-11 | 9999-01-01 |

| 18 | 10017 | d001 | 1993-08-03 | 9999-01-01 |

| 19 | 10018 | d004 | 1992-07-29 | 9999-01-01 |

| 20 | 10018 | d005 | 1987-04-03 | 1992-07-29 |

+--------+--------+---------+------------+------------+

20 rows in set (0.00 sec)

mysql>

原文:http://www.cnblogs.com/abclife/p/7473801.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值