Langsung ke konten utama

How To Get row_number in MySQL

 https://ubiq.co/database-blog/how-to-get-row_number-in-mysql/

SELECT t.*, @rownum := @rownum + 1 AS rank 
          FROM sales t, (SELECT @rownum := 0) r  
          order by amount desc;
 +------+---------------------+--------+------+
 | id   | order_date          | amount | rank |
 +------+---------------------+--------+------+
 |    1 | 2021-02-02 08:15:00 |    250 |    1 |
 |   10 | 2021-02-02 11:15:00 |    250 |    2 |
 |    5 | 2021-02-02 09:30:00 |    250 |    3 |
 |    9 | 2021-02-02 10:45:00 |    200 |    4 |
 |   12 | 2021-02-02 11:45:00 |    200 |    5 |
 |    6 | 2021-02-02 09:45:00 |    200 |    6 |
 |    2 | 2021-02-02 08:30:00 |    200 |    7 |
 |    7 | 2021-02-02 10:15:00 |    180 |    8 |
 |    3 | 2021-02-02 08:55:00 |    150 |    9 |
 |   11 | 2021-02-02 11:30:00 |    150 |   10 |
 |    4 | 2021-02-02 09:15:00 |    125 |   11 |
 |    8 | 2021-02-02 10:30:00 |    125 |   12 |
 +------+---------------------+--------+------+




Komentar

Postingan populer dari blog ini

CREATE CROSS TAB QUERY IN MYSQL

MySQL Multi-Aggregated Rows in Crosstab Queries MySQL’s crosstabs contain aggregate functions on two or more fields, presented in a tabular format. In a multi-aggregate crosstab query, two different functions can be applied to the same field or the same function can be applied to multiple fields on the same (row or column) axis. Rob Gravelle shows you how to apply two different functions to the same field in order to create grouping levels in the row axis. Today’s topic of discussion is crosstabs, which contain multiple aggregate functions in the row axis of a tabular resultset. Recall from the the  All About the Crosstab Query  article that an aggregate function is one that summarizes a group of related data in some way. Examples of aggregate functions include COUNT, SUM, AVG, MIN, and MAX. In a multi-aggregate crosstab query, two different functions can be applied to the same field or the same function can be applied to two or more fields. Today we’ll create a query...

Everything all about REGEX

 https://towardsdatascience.com/everything-you-need-to-know-about-regular-expressions-8f622fe10b03 Everything you need to know about Regular Expressions What is a Regular Expression? On an abstract level a regular expression, regex for short, is a shorthand representation for a set. A set of strings. Say we have a list of all valid zip codes. Instead of keeping that long and unwieldy list around, it’s often more practical to have a short and precise pattern that completely describes that set. Whenever you want to check whether a string is a valid zip code, you can match it against the pattern. You’ll get a true or false result indicating whether the string belongs to the set of zip codes the regex pattern represents. Let’s expand on the set of zip codes. A list of zip codes is finite, consists of rather short strings, and is not particularly challenging computationally. What about the set of strings that end in  .csv ? Can be quite useful when looking for data files. This set ...

Pentaho Data Integration: Membuat Koneksi ke database MSSQL Server 2008 R2

Untuk terhubung ke database SQL Server langkah-langkah berikut harus dilakukan:   Download Driver Microsoft JDBC di https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774  Tutup Spoon atau Kettle project  Unzip/extract paket dalam direktori temporer (bebas) Copy '<temp directory> \ sqljdbc_6.0\enu\auth\x64\ sqljdbc_auth.dll' ke 'C:\Program Files\Java\jre1.8.0_131' atau sesuaikan dengan path java runtime terinstall  Copy '<temp directory>\ sqljdbc_6.0\enu\jre8\sqljdbc42.jar' ke '<Kettle folder instalasi> \ data-integration \ lib' Buka Spoon atau Kettle project Uji koneksi dalam Spoon Hapus direktori temporer karena sudah tidak digunakan lagi Jika kita meng-upgrade Kettle, Java, JDBC Driver ke versi yang lebih tinggi, maka serangkaian langkah-langkah di atas harus diulang lagi.