Helle,
in my case:
table agdatum
artnr, nr, typ, stueckg, datum
1 1 2 100 01.01.2022
1 1 0 0 01.01.2022
1 1 2 22 05.01.2022
1 2 2 33 05.01.2022
2 1 0 0 06.01.2022
I would group all artnr, nr where the typ > 0 after the last datum and get the price (stueckg) for this position
In case of artnr 1 and ag 1 is it stueckg 22 from 05.01.2022.
My sql seems to be to complicated or not perfect:
with cte as(
select artnr, nr, typ, max(datum) as dt from agdatum where typ > 0 group by artnr, nr, typ)
select artnr, nr, typ, (select stueckg from agdatum where artnr = cte.artnr and nr = cte.nr and typ = cte.typ and datum = cte.dt) from cte
is there a better way?
Thanks in advance.
Best regards
Olaf
--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-support/000001d8f041%24501c6bd0%24f0554370%24%40satron.de.
Hello set,
first, thank you for your time. It is not my database design, I must import some data from another database, also firebird.
With your first cte I get more than the double amount of data, also typ 0 and typ null. With your second command I get a similar result as with my command. I'm amazed at how many options there are. Thank you so much, I think if there data still missing, they will be added manually.
Von: firebird...@googlegroups.com <firebird...@googlegroups.com> Im Auftrag von Svein Erling Tysvær
Gesendet: Freitag, 4. November 2022 13:21
An: firebird...@googlegroups.com
Betreff: Re: [firebird-support] Easier way?
Your solution seems OK, Olaf, but if there's only one record per day, then you could alternatively try
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-support/CAKC2LgyR6bmeA0egtn8haOAukPQXhZLQs6NZ_e21AJ4vS3A0mA%40mail.gmail.com.