Get the App
SLTechnology News&Howtos  ›  Database  › 

How to implement a statement with similar rownum function in MySQL

Shulou Source: shulou.com Published: 2022-05-31 18:23:03 09月25日 Update

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!

Tags: Sentence function content learning query practical deeper interest variable practical practical easy to operate method more friends website channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno MariaDB macOS Shulou Information