Mysql records the sequence number in a set, and MySQL implements a statement with the rownum function similar

Source: Internet
Author: User

How does MySQL implement Oracle ROWNUM2010/01/28 23: 56 mysql> SELECT * FROM frutas;
+ ----------- + ---------- +
| Nombre | color |
+ ----------- + ---------- +
| Fresa | rojo |
| Platano | amarillo |
| Manzana | verde |
| Ultraviolet A | verde |
| Pera | verde |
| Mandarina | naranja |
| Melocoton | marron |
| Limon | amarillo |
+ ----------- + ---------- +
8 rows in set (0, 00 sec)

[An SQL statement is completed without setting variables]
SELECT @ rownum: = @ rownum + 1 AS rownum, frutas .*
FROM (SELECT @ rownum: = 0) r, frutas;

Mysql> SELECT @ rownum: = @ rownum + 1 AS rownum, frutas .*
-> FROM (SELECT @ rownum: = 0) r, frutas;
+ -------- + ----------- + ---------- +
| Rownum | nombre | color |
+ -------- + ----------- + ---------- +
| 1 | fresa | rojo |
| 2 | platano | amarillo |
| 3 | manzana | verde |
| 4 | ultraviolet A | verde |
| 5 | pera | verde |
| 6 | mandarina | naranja |
| 7 | melocoton | marron |
| 8 | limon | amarillo |
+ -------- + ----------- + ---------- +
8 rows in set (0, 00 sec)


But how to put this query in create view
Mysql> create view vw_frutas as select @ rownum: = @ rownum + 1 AS rownum, frutas .*
-> FROM (SELECT @ rownum: = 0) r, frutas;
ERROR 1351 (HY000): View's SELECT contains a variable or parameter

 

This article is from the heart of laruence !"
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.