Subject | Re: How can I avoid temporary tables? |
---|---|
Author | c_pradelli |
Post date | 2002-11-06T17:08:01Z |
Hi Dimitry!
First at all, thank you for your responce.:)
different fields that are in the header to do this comparations.
I can't denormalize all the fields.
so it will run 4000 subselect.
Can I do something with views?
Best regards
Christian
First at all, thank you for your responce.:)
>You also can try to denormalize your data moving sell-date intoI know that but the sell-date is for this example, I use a lot of
>items. It would remove one table from SELECT and increase
> selectivity of the code-date index.
different fields that are in the header to do this comparations.
I can't denormalize all the fields.
> Try this:I already try this, is very slow because I have about 2000 products
>
> SELECT p.Code,
> (SELECT sum(i.amount) FROM items i JOIN header h
> ON i.billnumber=h.billnumber
> WHERE i.Code=p.Code AND h.date BETWEEN dateA1 AND dateA2)
> AS Sales1,
> /* I believe that every item has appropriate header */
> (SELECT sum(i.amount) FROM items i JOIN header h
> ON i.billnumber=h.billnumber
> WHERE i.Code=p.Code AND h.date BETWEEN dateB1 AND dateB2)
> AS Sales2
> FROM products p
> /* I also believe that you want all products codes in result record
> set even if this product wasn's sold in both periods */
so it will run 4000 subselect.
> Or you can try FULL JOIN of your SP_TEMPDATAs if you don't needto
> see non-sold product codes.I need to see the all the products.
Can I do something with views?
Best regards
Christian