database - SQL: Find filled area -


this question has answer here:

i have table:

create table coordinates (   x integer not null,   y integer not null,   color varchar(1) not null,   primary key(x,y) ) 

here sample data:

insert coordinates   (x, y, color) values   (0, 4, 'g'),   (1, 0, 'g'),   (1, 1, 'g'),   (1, 2, 'g'),   (1, 3, 'g'),   (0, 4, 'g'),   (1, 0, 'g'),   (1, 1, 'g'),   (1, 2, 'g'),   (1, 3, 'g'),   (1, 4, 'g'),   (2, 0, 'b'),   (2, 1, 'g'),   (2, 2, 'g'),   (2, 3, 'g'),   (2, 4, 'g'),   (4, 0, 'b'),   (4, 1, 'r'),   (4, 2, 'r'),   (4, 3, 'g'),   (4, 4, 'g'),   (6, 0, 'r'),   (6, 1, 'g'),   (6, 2, 'g'),   (6, 3, 'r'),   (6, 4, 'r') ; 

i trying write query finds largest-area rectangles. assuming rectangle defined bottom left , top right, , 1/4 r, 1/4 b, 1/4 g, 1/4 y.

so result should this:

x1 | y1 | x2 | y2 | area -------------------------  0    1    6    9     58  1    2    4    7     58 

make function calculates area , query function biggest one.


Comments

Popular posts from this blog

Python __call__ special method practical example -

arrays - jQuery - Retrieve values from HTML elements and return their sum -