zhilenko_myu
13th December 2021, 08:10
hello. why does not it work?
select *
from zrsfc500
where zrsfc500.orno between "M14018675" and "M14018700"
and zrsfc500.tipz = 2
and zrsfc500.ncwc = (select max(cc.ncwc) from zrsfc500 cc where cc.dtpn = zrsfc500.dtpn and cc.tipz = 2
and cc.orno = zrsfc500.orno)
selectdo
aa = 1
ncwc=zrsfc500.ncwc
endselect
you need to change the data, where the maximum ncwc. does not enter selectdo
mark_h
13th December 2021, 16:23
I would wait for someone that knows baan sql way better than me. My solution would be the simplest method and I would separate the 2 queries.
ee05220
13th December 2021, 19:15
hello. why does not it work?
select *
from zrsfc500
where zrsfc500.orno between "M14018675" and "M14018700"
and zrsfc500.tipz = 2
and zrsfc500.ncwc = (select max(cc.ncwc) from zrsfc500 cc where cc.dtpn = zrsfc500.dtpn and cc.tipz = 2
and cc.orno = zrsfc500.orno)
selectdo
aa = 1
ncwc=zrsfc500.ncwc
endselect
you need to change the data, where the maximum ncwc. does not enter selectdo
try
select *
from zrsfc500
where zrsfc500.orno between "M14018675" and "M14018700"
and zrsfc500.tipz = 2
and zrsfc500.ncwc in (select max(cc.ncwc) from zrsfc500 cc where cc.dtpn = zrsfc500.dtpn and cc.tipz = 2
and cc.orno = zrsfc500.orno)
selectdo
endselect
zhilenko_myu
16th December 2021, 02:13
try
select *
from zrsfc500
where zrsfc500.orno between "M14018675" and "M14018700"
and zrsfc500.tipz = 2
and zrsfc500.ncwc in (select max(cc.ncwc) from zrsfc500 cc where cc.dtpn = zrsfc500.dtpn and cc.tipz = 2
and cc.orno = zrsfc500.orno)
selectdo
endselect
does not work max, min, count and in
it turned out just like that:
SELECT bbb.ncwc:ncwc
FROM ( SELECT zrsfc500.orno as orno_, MIN( zrsfc500.ncwc ) AS max_ncwc, zrsfc500.dtpn as dtpn_
FROM zrsfc500
where zrsfc500.orno between "M14018675" and "M14018700"
GROUP BY zrsfc500.orno, zrsfc500.dtpn ) aaa
INNER JOIN
zrsfc500 AS bbb
ON aaa.max_ncwc = bbb.ncwc and aaa.orno_ = bbb.orno and aaa.dtpn_ = bbb.dtpn
selectdo
endselect
zhilenko_myu
16th December 2021, 08:59
it only worked like that
SELECT bbb.ncwc:ncwc
FROM ( SELECT zrsfc500.orno as orno_, MIN( zrsfc500.ncwc ) AS max_ncwc, zrsfc500.dtpn as dtpn_
FROM zrsfc500
where zrsfc500.orno between "M14018675" and "M14018700"
GROUP BY zrsfc500.orno, zrsfc500.dtpn ) aaa
INNER JOIN
zrsfc500 AS bbb
ON aaa.max_ncwc = bbb.ncwc and aaa.orno_ = bbb.orno and aaa.dtpn_ = bbb.dtpn
selectdo
endselect
mark_h
16th December 2021, 15:04
Thanks for posting the solution.