1. links: link_id, road
2. roads: road, code
2. admin_classes: code, admin_class, priority
So, for ONE LINK_ID I have several codes and several admin_class+priority raws But in result set i need only one row for each link_id: link_id and admin_class, that refers to min priority. I try to make sql statement, like following:
select l.link_id, ac.admin_class, min(ac.priority)
from base.links as l
inner join base.admin_classes as ac
on ac.code=l.code
where ac.admin_class<>0
但是,首先,它并不奏效,并非需要。 我只希望定下两栏——连接——直线和行政管理——
随后,我尝试如下:
select l.link_id, (select ac.admin_class from base.admin_classes as ac where ac.code=l.code
order by ac.priority limit 1) as admin_class from base.links as l
这是正确的,但我不知道如何增加内部选择的条件,我只需要拥有行政结构的原材料;和
I use PostgreSql 8.3
Thank you in advance.