ORACLE ROW_NUMBER () 函式轉成MySQL
阿新 • • 發佈:2019-01-02
copy
-
ORACLE :
- SELECT b.* , ROW_NUMBER () OVER ( PARTITION BY customer_name, dealer_code ORDER BY customer_no DESC) rank FROM tm_customer
-
MYSQL:
- SELECT b.*, IF(@pdept = CONCAT(b.customer_name, b.dealer_code),@rank := @rank + 1,@rank := 1) AS rank,
-
@pdept := CONCAT(b.customer_name, b.dealer_code),
-
@rownum := @rownum + 1
- FROM
- (SELECT b.* FROM tm_customer b ORDER BY CONCAT(b.customer_name, b.dealer_code) ASC, customer_no DESC) b,
- (SELECT @rownum := 0,@pdept := NULL,@rank := 0) a