Aviad Harell <[EMAIL PROTECTED]>
Thanks for your replay. I tried not to use user defined function to
do it. This code is working on SqlServer but on SQLite I get misuse
of aggregate: (SUM(SALES)).

Try this - it should do the same thing:

select c customer, p1 product, sum(case when s1 < s2 then 1 else 0 end) rank
from (
select t1.customer c,
       t1.product p1, sum(t1.sales)/count(distinct t2.rowid) s1,
       t2.product p2, sum(t2.sales)/count(distinct t1.rowid) s2
from Test1MX1000Multi  t1 join Test1MX1000Multi  t2
        on (t1.customer = t2.customer)
group by t1.customer, t1.product, t2.product
group by customer, product;

Igor Tandetnik

To unsubscribe, send email to [EMAIL PROTECTED]

Reply via email to