PostgreSQL interesting issue












-3















There are 5 relations:



Event (etype, description)                      primary key - etype

City (cname, country, population) primary key - cname

Disaster (cname, dyear, etype, casualties) primary keys - cname, dyear

Prediction (cname, etype, casualties) primary keys - cname, etype

Measures (etype, provider, mcost, percent) primary keys - etype, provider


etype - type of disaster.



provider - police, fire department...



mcost - cost of those providers.



percent - the percent of the providers to avoid casualties.



I need to write a query which finds out 2 successful providers for predicted disasters in a city. The cost for both must not be higher than 1,000,000.



2 Successful providers defined as the max percent possible summed.



I have this so far:



select
from prediction, measures as m1, measures as m2
where m1.provider < m2.provider AND (m1.mcost + m2.mcost <= 1000000)
AND m1.percent + m2.percent >= all (select


I don't know if this partial query right and what to do next.










share|improve this question























  • "I don't know if this partial query right" --- so run it and see?

    – zerkms
    Nov 18 '18 at 1:35











  • Run partial query? why?

    – Arthur
    Nov 18 '18 at 1:37











  • please learn to use explicit ANSI standard join syntax e.g. "inner join" "left outer join". Deny yourself the option of placing commas between table names in the from clause.

    – Used_By_Already
    Nov 18 '18 at 1:53






  • 2





    Why would anyone run a partial query? To see if that bit works. If no, fix it. If yes, go on to the next bit.

    – Used_By_Already
    Nov 18 '18 at 1:57






  • 2





    No **** thrown by me. You asked why someone would run a partial query. If you are unwilling to accept advice, fine, but there is no need to toss insults around. Running partial code is a valid approach to SQL.

    – Used_By_Already
    Nov 18 '18 at 6:32
















-3















There are 5 relations:



Event (etype, description)                      primary key - etype

City (cname, country, population) primary key - cname

Disaster (cname, dyear, etype, casualties) primary keys - cname, dyear

Prediction (cname, etype, casualties) primary keys - cname, etype

Measures (etype, provider, mcost, percent) primary keys - etype, provider


etype - type of disaster.



provider - police, fire department...



mcost - cost of those providers.



percent - the percent of the providers to avoid casualties.



I need to write a query which finds out 2 successful providers for predicted disasters in a city. The cost for both must not be higher than 1,000,000.



2 Successful providers defined as the max percent possible summed.



I have this so far:



select
from prediction, measures as m1, measures as m2
where m1.provider < m2.provider AND (m1.mcost + m2.mcost <= 1000000)
AND m1.percent + m2.percent >= all (select


I don't know if this partial query right and what to do next.










share|improve this question























  • "I don't know if this partial query right" --- so run it and see?

    – zerkms
    Nov 18 '18 at 1:35











  • Run partial query? why?

    – Arthur
    Nov 18 '18 at 1:37











  • please learn to use explicit ANSI standard join syntax e.g. "inner join" "left outer join". Deny yourself the option of placing commas between table names in the from clause.

    – Used_By_Already
    Nov 18 '18 at 1:53






  • 2





    Why would anyone run a partial query? To see if that bit works. If no, fix it. If yes, go on to the next bit.

    – Used_By_Already
    Nov 18 '18 at 1:57






  • 2





    No **** thrown by me. You asked why someone would run a partial query. If you are unwilling to accept advice, fine, but there is no need to toss insults around. Running partial code is a valid approach to SQL.

    – Used_By_Already
    Nov 18 '18 at 6:32














-3












-3








-3








There are 5 relations:



Event (etype, description)                      primary key - etype

City (cname, country, population) primary key - cname

Disaster (cname, dyear, etype, casualties) primary keys - cname, dyear

Prediction (cname, etype, casualties) primary keys - cname, etype

Measures (etype, provider, mcost, percent) primary keys - etype, provider


etype - type of disaster.



provider - police, fire department...



mcost - cost of those providers.



percent - the percent of the providers to avoid casualties.



I need to write a query which finds out 2 successful providers for predicted disasters in a city. The cost for both must not be higher than 1,000,000.



2 Successful providers defined as the max percent possible summed.



I have this so far:



select
from prediction, measures as m1, measures as m2
where m1.provider < m2.provider AND (m1.mcost + m2.mcost <= 1000000)
AND m1.percent + m2.percent >= all (select


I don't know if this partial query right and what to do next.










share|improve this question














There are 5 relations:



Event (etype, description)                      primary key - etype

City (cname, country, population) primary key - cname

Disaster (cname, dyear, etype, casualties) primary keys - cname, dyear

Prediction (cname, etype, casualties) primary keys - cname, etype

Measures (etype, provider, mcost, percent) primary keys - etype, provider


etype - type of disaster.



provider - police, fire department...



mcost - cost of those providers.



percent - the percent of the providers to avoid casualties.



I need to write a query which finds out 2 successful providers for predicted disasters in a city. The cost for both must not be higher than 1,000,000.



2 Successful providers defined as the max percent possible summed.



I have this so far:



select
from prediction, measures as m1, measures as m2
where m1.provider < m2.provider AND (m1.mcost + m2.mcost <= 1000000)
AND m1.percent + m2.percent >= all (select


I don't know if this partial query right and what to do next.







sql postgresql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '18 at 1:31









ArthurArthur

286




286













  • "I don't know if this partial query right" --- so run it and see?

    – zerkms
    Nov 18 '18 at 1:35











  • Run partial query? why?

    – Arthur
    Nov 18 '18 at 1:37











  • please learn to use explicit ANSI standard join syntax e.g. "inner join" "left outer join". Deny yourself the option of placing commas between table names in the from clause.

    – Used_By_Already
    Nov 18 '18 at 1:53






  • 2





    Why would anyone run a partial query? To see if that bit works. If no, fix it. If yes, go on to the next bit.

    – Used_By_Already
    Nov 18 '18 at 1:57






  • 2





    No **** thrown by me. You asked why someone would run a partial query. If you are unwilling to accept advice, fine, but there is no need to toss insults around. Running partial code is a valid approach to SQL.

    – Used_By_Already
    Nov 18 '18 at 6:32



















  • "I don't know if this partial query right" --- so run it and see?

    – zerkms
    Nov 18 '18 at 1:35











  • Run partial query? why?

    – Arthur
    Nov 18 '18 at 1:37











  • please learn to use explicit ANSI standard join syntax e.g. "inner join" "left outer join". Deny yourself the option of placing commas between table names in the from clause.

    – Used_By_Already
    Nov 18 '18 at 1:53






  • 2





    Why would anyone run a partial query? To see if that bit works. If no, fix it. If yes, go on to the next bit.

    – Used_By_Already
    Nov 18 '18 at 1:57






  • 2





    No **** thrown by me. You asked why someone would run a partial query. If you are unwilling to accept advice, fine, but there is no need to toss insults around. Running partial code is a valid approach to SQL.

    – Used_By_Already
    Nov 18 '18 at 6:32

















"I don't know if this partial query right" --- so run it and see?

– zerkms
Nov 18 '18 at 1:35





"I don't know if this partial query right" --- so run it and see?

– zerkms
Nov 18 '18 at 1:35













Run partial query? why?

– Arthur
Nov 18 '18 at 1:37





Run partial query? why?

– Arthur
Nov 18 '18 at 1:37













please learn to use explicit ANSI standard join syntax e.g. "inner join" "left outer join". Deny yourself the option of placing commas between table names in the from clause.

– Used_By_Already
Nov 18 '18 at 1:53





please learn to use explicit ANSI standard join syntax e.g. "inner join" "left outer join". Deny yourself the option of placing commas between table names in the from clause.

– Used_By_Already
Nov 18 '18 at 1:53




2




2





Why would anyone run a partial query? To see if that bit works. If no, fix it. If yes, go on to the next bit.

– Used_By_Already
Nov 18 '18 at 1:57





Why would anyone run a partial query? To see if that bit works. If no, fix it. If yes, go on to the next bit.

– Used_By_Already
Nov 18 '18 at 1:57




2




2





No **** thrown by me. You asked why someone would run a partial query. If you are unwilling to accept advice, fine, but there is no need to toss insults around. Running partial code is a valid approach to SQL.

– Used_By_Already
Nov 18 '18 at 6:32





No **** thrown by me. You asked why someone would run a partial query. If you are unwilling to accept advice, fine, but there is no need to toss insults around. Running partial code is a valid approach to SQL.

– Used_By_Already
Nov 18 '18 at 6:32












2 Answers
2






active

oldest

votes


















1














Consider calculating two CTEs: all distinct provider pairs and the max percent of each pair. Then join the two CTEs in main query:



WITH provider_pairs AS (
SELECT m1.provider AS provider1, m2.provider AS provider2,
m1.percent + m2.percent AS sum_percent
FROM measures m1
INNER JOIN measures m2 ON m1.provider < m2.provider
INNER JOIN prediction p ON p.etype = m1.etype AND p.etype = m2.etype
WHERE (m1.mcost + m2.mcost <= 1000000)
),
max_pct AS (
SELECT MAX(sum_percent) AS max_percent
FROM provider_pairs p
)

SELECT p.provider1, p.provider2
FROM provider_pairs p
INNER JOIN max_pct m ON p.sum_percent = m.max_percent





share|improve this answer
























  • The part of max_pct... (rows 9-11) is connected to the WITH clause?

    – Arthur
    Nov 18 '18 at 4:45











  • And also i can't understand how it'll choose the pair with the max percent

    – Arthur
    Nov 18 '18 at 6:06











  • WITH defines the CTEs which can be one or comma separated list of more than one. The last SELECT statement's JOIN clause chooses the pair with max percent (which can be more than one pair due to ties) as it joins both CTEs.

    – Parfait
    Nov 18 '18 at 14:13





















0














If i got the question correct, you are looking for all pairs of providers from measures table whose combined mcost is less than 100000 and whose combined percentage is the maximum



See if the following helps
One way of doing this would be as follows




  1. Cartesian product the tables and filter out the self join condition

  2. Sum up the percentage column and sum up the mcost colum

  3. Filter out summed_up mcost to be <100000

  4. order by summed_up percentage desc and get the first value.


I created a test case as follows



create table measures(provider varchar(50),mcost int, percent int);

insert into measures values('Police',30000,80);
insert into measures values('Fire Department',50000,40);
insert into measures values('Military',40000,50);
insert into measures values('Medical',45000,70);

select * from (
select row_number() over(order by x.max_percent desc) as rnk
,x.*
from (
select a.provider
,b.provider
,greatest(a.provider,b.provider) as combo_pair
,a.percent+b.percent as summed_percent
,a.mcost+b.mcost as summed_mcost
,max(a.percent+b.percent) over(partition by greatest(a.provider,b.provider)) as max_percent
from measures a
join measures b
on 1=1
where a.provider <> b.provider
and a.mcost+b.mcost <100000 /*Check for the combined cost to be <100000*/
)x
where x.max_percent=x.summed_percent
)y
where y.rnk=1


Updated DEMO
https://dbfiddle.uk/?rdbms=postgres_8.4&fiddle=7db3297721500ee926c590207a1e57e7






share|improve this answer


























  • i forgot to mention that i am not allowed to use neither order by nor limit here :)

    – Arthur
    Nov 18 '18 at 4:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357131%2fpostgresql-interesting-issue%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Consider calculating two CTEs: all distinct provider pairs and the max percent of each pair. Then join the two CTEs in main query:



WITH provider_pairs AS (
SELECT m1.provider AS provider1, m2.provider AS provider2,
m1.percent + m2.percent AS sum_percent
FROM measures m1
INNER JOIN measures m2 ON m1.provider < m2.provider
INNER JOIN prediction p ON p.etype = m1.etype AND p.etype = m2.etype
WHERE (m1.mcost + m2.mcost <= 1000000)
),
max_pct AS (
SELECT MAX(sum_percent) AS max_percent
FROM provider_pairs p
)

SELECT p.provider1, p.provider2
FROM provider_pairs p
INNER JOIN max_pct m ON p.sum_percent = m.max_percent





share|improve this answer
























  • The part of max_pct... (rows 9-11) is connected to the WITH clause?

    – Arthur
    Nov 18 '18 at 4:45











  • And also i can't understand how it'll choose the pair with the max percent

    – Arthur
    Nov 18 '18 at 6:06











  • WITH defines the CTEs which can be one or comma separated list of more than one. The last SELECT statement's JOIN clause chooses the pair with max percent (which can be more than one pair due to ties) as it joins both CTEs.

    – Parfait
    Nov 18 '18 at 14:13


















1














Consider calculating two CTEs: all distinct provider pairs and the max percent of each pair. Then join the two CTEs in main query:



WITH provider_pairs AS (
SELECT m1.provider AS provider1, m2.provider AS provider2,
m1.percent + m2.percent AS sum_percent
FROM measures m1
INNER JOIN measures m2 ON m1.provider < m2.provider
INNER JOIN prediction p ON p.etype = m1.etype AND p.etype = m2.etype
WHERE (m1.mcost + m2.mcost <= 1000000)
),
max_pct AS (
SELECT MAX(sum_percent) AS max_percent
FROM provider_pairs p
)

SELECT p.provider1, p.provider2
FROM provider_pairs p
INNER JOIN max_pct m ON p.sum_percent = m.max_percent





share|improve this answer
























  • The part of max_pct... (rows 9-11) is connected to the WITH clause?

    – Arthur
    Nov 18 '18 at 4:45











  • And also i can't understand how it'll choose the pair with the max percent

    – Arthur
    Nov 18 '18 at 6:06











  • WITH defines the CTEs which can be one or comma separated list of more than one. The last SELECT statement's JOIN clause chooses the pair with max percent (which can be more than one pair due to ties) as it joins both CTEs.

    – Parfait
    Nov 18 '18 at 14:13
















1












1








1







Consider calculating two CTEs: all distinct provider pairs and the max percent of each pair. Then join the two CTEs in main query:



WITH provider_pairs AS (
SELECT m1.provider AS provider1, m2.provider AS provider2,
m1.percent + m2.percent AS sum_percent
FROM measures m1
INNER JOIN measures m2 ON m1.provider < m2.provider
INNER JOIN prediction p ON p.etype = m1.etype AND p.etype = m2.etype
WHERE (m1.mcost + m2.mcost <= 1000000)
),
max_pct AS (
SELECT MAX(sum_percent) AS max_percent
FROM provider_pairs p
)

SELECT p.provider1, p.provider2
FROM provider_pairs p
INNER JOIN max_pct m ON p.sum_percent = m.max_percent





share|improve this answer













Consider calculating two CTEs: all distinct provider pairs and the max percent of each pair. Then join the two CTEs in main query:



WITH provider_pairs AS (
SELECT m1.provider AS provider1, m2.provider AS provider2,
m1.percent + m2.percent AS sum_percent
FROM measures m1
INNER JOIN measures m2 ON m1.provider < m2.provider
INNER JOIN prediction p ON p.etype = m1.etype AND p.etype = m2.etype
WHERE (m1.mcost + m2.mcost <= 1000000)
),
max_pct AS (
SELECT MAX(sum_percent) AS max_percent
FROM provider_pairs p
)

SELECT p.provider1, p.provider2
FROM provider_pairs p
INNER JOIN max_pct m ON p.sum_percent = m.max_percent






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 18 '18 at 3:13









ParfaitParfait

51.2k84370




51.2k84370













  • The part of max_pct... (rows 9-11) is connected to the WITH clause?

    – Arthur
    Nov 18 '18 at 4:45











  • And also i can't understand how it'll choose the pair with the max percent

    – Arthur
    Nov 18 '18 at 6:06











  • WITH defines the CTEs which can be one or comma separated list of more than one. The last SELECT statement's JOIN clause chooses the pair with max percent (which can be more than one pair due to ties) as it joins both CTEs.

    – Parfait
    Nov 18 '18 at 14:13





















  • The part of max_pct... (rows 9-11) is connected to the WITH clause?

    – Arthur
    Nov 18 '18 at 4:45











  • And also i can't understand how it'll choose the pair with the max percent

    – Arthur
    Nov 18 '18 at 6:06











  • WITH defines the CTEs which can be one or comma separated list of more than one. The last SELECT statement's JOIN clause chooses the pair with max percent (which can be more than one pair due to ties) as it joins both CTEs.

    – Parfait
    Nov 18 '18 at 14:13



















The part of max_pct... (rows 9-11) is connected to the WITH clause?

– Arthur
Nov 18 '18 at 4:45





The part of max_pct... (rows 9-11) is connected to the WITH clause?

– Arthur
Nov 18 '18 at 4:45













And also i can't understand how it'll choose the pair with the max percent

– Arthur
Nov 18 '18 at 6:06





And also i can't understand how it'll choose the pair with the max percent

– Arthur
Nov 18 '18 at 6:06













WITH defines the CTEs which can be one or comma separated list of more than one. The last SELECT statement's JOIN clause chooses the pair with max percent (which can be more than one pair due to ties) as it joins both CTEs.

– Parfait
Nov 18 '18 at 14:13







WITH defines the CTEs which can be one or comma separated list of more than one. The last SELECT statement's JOIN clause chooses the pair with max percent (which can be more than one pair due to ties) as it joins both CTEs.

– Parfait
Nov 18 '18 at 14:13















0














If i got the question correct, you are looking for all pairs of providers from measures table whose combined mcost is less than 100000 and whose combined percentage is the maximum



See if the following helps
One way of doing this would be as follows




  1. Cartesian product the tables and filter out the self join condition

  2. Sum up the percentage column and sum up the mcost colum

  3. Filter out summed_up mcost to be <100000

  4. order by summed_up percentage desc and get the first value.


I created a test case as follows



create table measures(provider varchar(50),mcost int, percent int);

insert into measures values('Police',30000,80);
insert into measures values('Fire Department',50000,40);
insert into measures values('Military',40000,50);
insert into measures values('Medical',45000,70);

select * from (
select row_number() over(order by x.max_percent desc) as rnk
,x.*
from (
select a.provider
,b.provider
,greatest(a.provider,b.provider) as combo_pair
,a.percent+b.percent as summed_percent
,a.mcost+b.mcost as summed_mcost
,max(a.percent+b.percent) over(partition by greatest(a.provider,b.provider)) as max_percent
from measures a
join measures b
on 1=1
where a.provider <> b.provider
and a.mcost+b.mcost <100000 /*Check for the combined cost to be <100000*/
)x
where x.max_percent=x.summed_percent
)y
where y.rnk=1


Updated DEMO
https://dbfiddle.uk/?rdbms=postgres_8.4&fiddle=7db3297721500ee926c590207a1e57e7






share|improve this answer


























  • i forgot to mention that i am not allowed to use neither order by nor limit here :)

    – Arthur
    Nov 18 '18 at 4:50
















0














If i got the question correct, you are looking for all pairs of providers from measures table whose combined mcost is less than 100000 and whose combined percentage is the maximum



See if the following helps
One way of doing this would be as follows




  1. Cartesian product the tables and filter out the self join condition

  2. Sum up the percentage column and sum up the mcost colum

  3. Filter out summed_up mcost to be <100000

  4. order by summed_up percentage desc and get the first value.


I created a test case as follows



create table measures(provider varchar(50),mcost int, percent int);

insert into measures values('Police',30000,80);
insert into measures values('Fire Department',50000,40);
insert into measures values('Military',40000,50);
insert into measures values('Medical',45000,70);

select * from (
select row_number() over(order by x.max_percent desc) as rnk
,x.*
from (
select a.provider
,b.provider
,greatest(a.provider,b.provider) as combo_pair
,a.percent+b.percent as summed_percent
,a.mcost+b.mcost as summed_mcost
,max(a.percent+b.percent) over(partition by greatest(a.provider,b.provider)) as max_percent
from measures a
join measures b
on 1=1
where a.provider <> b.provider
and a.mcost+b.mcost <100000 /*Check for the combined cost to be <100000*/
)x
where x.max_percent=x.summed_percent
)y
where y.rnk=1


Updated DEMO
https://dbfiddle.uk/?rdbms=postgres_8.4&fiddle=7db3297721500ee926c590207a1e57e7






share|improve this answer


























  • i forgot to mention that i am not allowed to use neither order by nor limit here :)

    – Arthur
    Nov 18 '18 at 4:50














0












0








0







If i got the question correct, you are looking for all pairs of providers from measures table whose combined mcost is less than 100000 and whose combined percentage is the maximum



See if the following helps
One way of doing this would be as follows




  1. Cartesian product the tables and filter out the self join condition

  2. Sum up the percentage column and sum up the mcost colum

  3. Filter out summed_up mcost to be <100000

  4. order by summed_up percentage desc and get the first value.


I created a test case as follows



create table measures(provider varchar(50),mcost int, percent int);

insert into measures values('Police',30000,80);
insert into measures values('Fire Department',50000,40);
insert into measures values('Military',40000,50);
insert into measures values('Medical',45000,70);

select * from (
select row_number() over(order by x.max_percent desc) as rnk
,x.*
from (
select a.provider
,b.provider
,greatest(a.provider,b.provider) as combo_pair
,a.percent+b.percent as summed_percent
,a.mcost+b.mcost as summed_mcost
,max(a.percent+b.percent) over(partition by greatest(a.provider,b.provider)) as max_percent
from measures a
join measures b
on 1=1
where a.provider <> b.provider
and a.mcost+b.mcost <100000 /*Check for the combined cost to be <100000*/
)x
where x.max_percent=x.summed_percent
)y
where y.rnk=1


Updated DEMO
https://dbfiddle.uk/?rdbms=postgres_8.4&fiddle=7db3297721500ee926c590207a1e57e7






share|improve this answer















If i got the question correct, you are looking for all pairs of providers from measures table whose combined mcost is less than 100000 and whose combined percentage is the maximum



See if the following helps
One way of doing this would be as follows




  1. Cartesian product the tables and filter out the self join condition

  2. Sum up the percentage column and sum up the mcost colum

  3. Filter out summed_up mcost to be <100000

  4. order by summed_up percentage desc and get the first value.


I created a test case as follows



create table measures(provider varchar(50),mcost int, percent int);

insert into measures values('Police',30000,80);
insert into measures values('Fire Department',50000,40);
insert into measures values('Military',40000,50);
insert into measures values('Medical',45000,70);

select * from (
select row_number() over(order by x.max_percent desc) as rnk
,x.*
from (
select a.provider
,b.provider
,greatest(a.provider,b.provider) as combo_pair
,a.percent+b.percent as summed_percent
,a.mcost+b.mcost as summed_mcost
,max(a.percent+b.percent) over(partition by greatest(a.provider,b.provider)) as max_percent
from measures a
join measures b
on 1=1
where a.provider <> b.provider
and a.mcost+b.mcost <100000 /*Check for the combined cost to be <100000*/
)x
where x.max_percent=x.summed_percent
)y
where y.rnk=1


Updated DEMO
https://dbfiddle.uk/?rdbms=postgres_8.4&fiddle=7db3297721500ee926c590207a1e57e7







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 18 '18 at 5:05

























answered Nov 18 '18 at 3:20









George JosephGeorge Joseph

1,47559




1,47559













  • i forgot to mention that i am not allowed to use neither order by nor limit here :)

    – Arthur
    Nov 18 '18 at 4:50



















  • i forgot to mention that i am not allowed to use neither order by nor limit here :)

    – Arthur
    Nov 18 '18 at 4:50

















i forgot to mention that i am not allowed to use neither order by nor limit here :)

– Arthur
Nov 18 '18 at 4:50





i forgot to mention that i am not allowed to use neither order by nor limit here :)

– Arthur
Nov 18 '18 at 4:50


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357131%2fpostgresql-interesting-issue%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini