Perform a self JOIN on the Points table to create all possible pairs of points.
Use the ON clause to ensure that we only consider pairs where the first point has a lower id than the second point to avoid duplicates.
In the WHERE clause, filter out pairs where the x or y coordinates are the same, as these would result in a zero area.
Calculate the area of the rectangle for each pair using the absolute difference between the x coordinates multiplied by the absolute difference between the y coordinates.
Order the results by area in descending order, then by the first point's id, and finally by the second point's id in ascending order.
Select the ids of the two points and the calculated area in the SELECT clause.
erDiagram
Points {
int id PK
int x_value
int y_value
}
Cross Join with Filtering and Conditional Ordering