Re: SQL dealing with subquery
От | Bryan Emrys |
---|---|
Тема | Re: SQL dealing with subquery |
Дата | |
Msg-id | eee4647d0801160934n3efe1e28h5a7c1e1cb5edf1ad@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: SQL dealing with subquery (Bryan Emrys <bryan.emrys@gmail.com>) |
Список | pgsql-sql |
<br />Following up my treaty rate thoughts, if I'm trying to get the lowest treaty payee (and rate) from a specific listof payees for every possible payor country, the following seems to work, but is it right? I'm specifically wonderingabout the group by clauses. (Or if there is a better way.) [table treaties has columns payor,payee,rate and in thissample, I'm just trying to find which country payee between Ireland and the Netherlands has the lowest rate from eachindividual payor country.] <br /><br />select a.payor,a.payee,a.rate<br />from treaties a,<br /><br />(select payor,min(rentr)from treaties<br />where payee in ('Ireland','Netherlands') group by payor<br />) b<br /><br />where a.payor=b.payor<br/>and a.rate = b.min<br />and payee in ('Ireland','Netherlands')<br />group by a.payor, a.payee, a.rate<br/>
В списке pgsql-sql по дате отправления: