`rank() OVER (PARTITION BY f1 ORDER BY f2 DESC) `
```ROW_NUMBER() () OVER (PARTITION BY f1 ORDER BY f2 DESC)  For each matching f1 Field generates a line number , And in accordance with the f2 Sort
Example select DID,customerID,totalPrice,ROW_NUMBER() over(order by totalPrice) as rows from OP_Order```

` Users can talk about horizontal comparison after sorting multi column data , for example ,oe An inquiry for , After making an inquiry to multiple suppliers , Need to take before 3 The price of each supplier is shown in a horizontal column .`
```select
product_id,
product_qty,
max(part1) as parter1,
max(price1) as price1,
max(part2) as parter2,
max(price2) as price2,
max(part3) as parter3,
max(price3) as price3
from(
select
product_id, product_qty,
case when abc=1 then partner_id end as part1,
case when abc=2 then partner_id end as part2,
case when abc=3 then partner_id end as part3,
case when abc=1 then price_unit end as price1,
case when abc=2 then price_unit end as price2,
case when abc=3 then price_unit end as price3
from (
select
pol.id, pol.product_id, pol.partner_id, product_qty , pol.price_unit,
rank() OVER (PARTITION BY pol.product_id order by pol.partner_id) as abc
from
purchase_requisition as rq
left join purchase_order as po on (po.requisition_id = rq.id)
left join purchase_order_line as pol on (pol.order_id = po.id)
where rq.id = 44
) as t
) as tt group by product_id,product_qty
```

give the result as follows ：

## psql rank row More articles about

1. 【 linear algebra 】3-3: Rank (Rank)

title: [ linear algebra ]3-3: Rank (Rank) categories: Mathematic Linear Algebra keywords: Rank Row Reduced form Pivot ...

2. 【 original 】 Open source .NET Arrange and assemble components KwCombinatorics Use ( 3、 ... and )—— Cartesian product combination

The total catalog of all articles in this blog : Blog contents - Real time updates The rest of this blog .NET Open source project article directory :[ Catalog ] The rest of this blog .NET Open source project article directory KwCombinatorics Component article directory : 1. ...

3. 【 original 】 Open source .NET Arrange and assemble components KwCombinatorics Use ( Two )—— Permutation generates

The total catalog of all articles in this blog : Blog contents - Real time updates The rest of this blog .NET Open source project article directory :[ Catalog ] The rest of this blog .NET Open source project article directory KwCombinatorics Component article directory : 1. ...

4. 【 original 】 Open source .NET Arrange and assemble components KwCombinatorics Use ( One )— Combinatorial generation

The total catalog of all articles in this blog : Blog contents - Real time updates The rest of this blog .NET Open source project article directory :[ Catalog ] The rest of this blog .NET Open source project article directory KwCombinatorics Component article directory : 1. ...

5. Python Batch processing CSV file

#encoding: utf-8 __author__ = 'DELL' import csv import glob import datetime import sys import os rel ...

6. Sqlite Quickly insert data into local tables

Original use Insert The method is too slow , I found... On the Internet https://www.cnblogs.com/yisen-code/p/6897524.html The train of thought is : Open transaction , Start pretreatment , And then put SQL Pass in specific values with parameters to ...

7. Python The toolkit [1] -&gt; pandas Data preprocessing -&gt; pandas Library and use summary

pandas Data preprocessing / pandas data pre-processing Catalog About pandas pandas library pandas Basic operation pandas Calculation pandas Of Series ...

8. Step by step towards the international garbled competition -- A spoof C Language

Everyone has been emphasizing standard coding . But there is a competition in the world for masters to entertain -- International garbled competition . What can be written is a deep understanding of the language master. I never thought I could " A spoof "C, It's always been honest coding . Just a few days ago ...

9. PostgreSQL Replication Chapter five Set up synchronous replication （1）

up to now , We've dealt with file based replication ( Or log shipping ) And simple stream based replication settings . In two cases , stay master After the last transaction is committed , The data is submitted , from slave receive . stay master Submit and slave It's actually completely grounded ...

## Random recommendation

1. Effective Java 40 Design method signatures carefully

Principle Choose method names carefully. Don't go overboard in providing convenience methods. Avoid ...

2. JQuery Traverse the specified id Of div name There are several ways to calculate the value

JQuery Traverse the specified id Of div name There are several ways to calculate the value : Method 1 \$("#div1 :text").each(function () { var this_id = \$(this). ...

3. JS in Date.parse Method returns NaN Solution

Date.parse() Method : // Convert the time string to seconds var date_str = '2013-12-3 18:32:00'; alert(date_str.replace(/-/g,'/')) ...

4. awk The use of multiple arrays

#!/bin/bash awk 'BEGIN{printf "%-60s %-10s %-10s %-10s\n","url","count" ...

5. iOS Open source library -- The most complete arrangement

6. MySQL Query duplicate data , And partial and complete field de duplication

1. Look up redundant duplicate records in the table ( Multiple fields ) select * from vitae a where (a.peopleId,a.seq) in  (select peopleId,seq from vit ...

7. Maven Remove the project version number when packing

Maven After packing ,jar or war The file name contains the version number information , Such as projectname0.0.1-SNAPSHOT.jar etc. , How to get rid of it ? terms of settlement : Open the project pom.xml file , stay <build> ...

8. 1.9 Distributed coordination services -Zookeeper( One )

Preface The characteristics of distributed environment Distribution concurrency During the operation of the program , Concurrent operations are common . For example, multiple nodes in the same distributed system , Access a shared resource at the same time . database . Distributed storage Disorder Message communication between processes , There will be inconsistent order ...

9. Android 5.0 edition USB Debug mode open method

Android 4.2 edition USB Debug mode open method 1. Get into “ Set up ” page , Click on “ About tablets ”. See the red box below .   2. Crazy Click “ Version number ”, See the red box below , Until it appears “ You are now in developer mode !” ...

10. use windows The performance monitor detects sqlserver Common indicators