Tema: Re: Reikia pagalbos su sql
Autorius: Raimis
Data: 2013-10-10 10:25:55
Pamegink taip:

 select a.client_id, a.client_name, a.dd, tbl2.order_no from (select
tbl1.client_id, tbl1.client_name, max(tbl2.order_date) from tbl1, tbl2
where tbl1.client_id=tbl2.client_id group by 1,2) a, tbl2 where
 tbl2.client_id = a.client_id and tbl2.order_date = a.dd

UNION ALL

SELECT client_id, Null As client_name, Null As order_no FROM tbl1 WHERE 
client_id  NOT IN  ( SELECT DISTINCT client_id FROM tbl2)

"HyperLink" <tomas.bagdonas@gmail.com> wrote in message 
news:l35iqt$dqa$1@trimpas.omnitel.net...
> Dėkui už pagalbą. Kaip ir viskas ok būtų, bet reikėtų, kad rodytų ir tuos 
> klientus, kurie neturėjo orderių - prie order_date ir order_no būtų tuščia 
> ar null.
>
> "babonis"  parašė naujienų news:l33d98$q09$1@trimpas.omnitel.net...
>
> pabandyk
>
> select a.client_id, a.client_name, a.dd, tbl2.order_no from (select
> tbl1.client_id, tbl1.client_name, max(tbl2.order_date) from tbl1, tbl2
> where tbl1.client_id=tbl2.client_id group by 1,2) a, tbl2 where
> tbl2.client_id = a.client_id and tbl2.order_date = a.dd
>
> On 10/09/2013 01:33 PM, HyperLink wrote:
>> Yra dvi lentelės:
>>
>> 1. lentelė
>>
>> client_id
>> client_name
>>
>> 2. lentelė
>>
>> client_id
>> order_date
>> order_no
>>
>>
>>
>> Reikia atrinkti kiekvieno kliento paskutinį orderį pagal orderio datą ir
>> būtent to orderio numerį:
>>
>> client_id, client_name,  order_date, order_no
>>
>>
>> Gal kas galite pagelbėti šioje situacijoje?
>>
>