How to implement a statement with similar rownum function in MySQL
This article mainly explains "how to realize the sentence with similar function of rownum in MySQL". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to achieve sentences with similar rownum functions in MySQL".
How to implement ROWNUM2010/01/28 23:56 > SELECT * FROM frutas of Oracle by MySQL
+-+ +
| | nombre | color |
+-+ +
| | fresa | rojo |
| | platano | amarillo |
| | manzana | verde |
| | uva | verde |
| | pera | verde |
| | mandarina | naranja |
| | melocoton | marron |
| | limon | amarillo |
+-+ +
8 rows in set (01.00 sec)
[a sql statement is completed without set 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 | uva | verde |
| | 5 | pera | verde |
| | 6 | mandarina | naranja |
| | 7 | melocoton | marron |
| | 8 | limon | amarillo |
+-+
8 rows in set (01.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
At this point, I believe you have a deeper understanding of "how to achieve statements similar to rownum functions in MySQL". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!