Sytze de Boer wrote:
> Hi folk
> I have a table where amongst other fields, I have empcode C(10), gross
> N(10,2), cycle N(5)
> empcode is the employee code, gross is total pay, cycle is the pay number
>
> I want to:
> select empcode, sum(gross) from mytable order by empcode group by
> empcode into table newtable
> BUT I ONLY WANT THE LAST 52 CYCLES (Some may have 300 cycles)
> Some may only have (say) 30 cycles
>
> Is this feasible ?
>
if you want the cycles with the biggest 52 numbers :
select empcode ;
into cursor newtable ;
from mytable my ;
where my.cycle in (SELECT TOP 52 aux.cycle ;
from mytable as aux ;
order by cycle desc) ;
order by empcode ;
group by empcode
If you want the last 52 cycles (sequentially last) :
select empcode ;
into cursor newtable ;
from mytable my ;
where my.cycle in (SELECT x.cycle ;
FROM (SELECT TOP 52 aux.cycle, RECNO();
from mytable as aux ;
order by 2 desc) as x) ;
order by empcode ;
group by empcode
> Regards
> Sytze
>
>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.