我必须根据数据库中的最小和最大日期进行查询,但是下面的查询似乎不正确,我怎样才能根据最小和最大日期获得结果。
select s.new_state as State,d.new_dist as District,b.ifBook as Book,sum(a.amt) as Amount
from
mtrans a
JOIN
isbn b
on
b.isbnd=a.isbn
and
a.orgdate
between
min(a.orgdate) and max(a.orgdate)
JOIN
user c
on
a.excd=c.mtrans
JOIN
state_mapping s
on
b.state=s.org_state
JOIN
dist_mapping d
on
b.dist=d.org_dist
where
TRIM(b.ifBook) <> ''
and
b.ifBook IS NOT NULL
and
b.ifBook not like '%TRAVAN%'
and
TRIM(d.new_dist) <> ''
and
d.new_dist IS NOT NULL
group by
b.ifBook,d.new_dist,s.new_state