Subject | Re: [firebird-support] Re: SQL Problem |
---|---|
Author | Arno Brinkman |
Post date | 2004-11-09T18:09:13Z |
Hi,
this by splitting it into two queries.
Create a VIEW (fe VIEW1) with
SELECT
id_apos,
Count(distinct f_id_auftrag) AS f_id_auftrag,
Count(distinct f_id_kunde) AS f_id_kunde,
Min(f_weight) AS f_weight,
Sum(f_quantity) AS f_quantity
FROM
t_apos ...
JOIN...
WHERE
...
GROUP BY
id_apos
and use the VIEW in a select
SELECT
Count(*),
Sum(f_id_auftrag),
Sum(f_id_kunde),
Sum(f_weight),
Sum(f_quantity)
FROM
VIEW1
The problem is that the WHERE clause is going into the VIEW and when that is
dynamic it is not possible. In that case then you've to write a Stored
Procedure where you can do it all as you want :)
Regards,
Arno Brinkman
ABVisie
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/
Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com
Nederlandse firebird nieuwsgroep :
news://80.126.130.81
> > selectI still not completly understand what you want, but may be you can achieve
> > Count(distinct id_apos),
> > Count(distinct f_id_auftrag),
> > Count(distinct f_id_kunde),
> > Min(f_weight),
> > Sum(f_quantity)
> > FROM
> > t_apos ...
> > JOIN...
> > WHERE ...
> >
>
> this only gives me the lowest weight, not the sum of all weights (counted
> only one time for every id_apos).
this by splitting it into two queries.
Create a VIEW (fe VIEW1) with
SELECT
id_apos,
Count(distinct f_id_auftrag) AS f_id_auftrag,
Count(distinct f_id_kunde) AS f_id_kunde,
Min(f_weight) AS f_weight,
Sum(f_quantity) AS f_quantity
FROM
t_apos ...
JOIN...
WHERE
...
GROUP BY
id_apos
and use the VIEW in a select
SELECT
Count(*),
Sum(f_id_auftrag),
Sum(f_id_kunde),
Sum(f_weight),
Sum(f_quantity)
FROM
VIEW1
The problem is that the WHERE clause is going into the VIEW and when that is
dynamic it is not possible. In that case then you've to write a Stored
Procedure where you can do it all as you want :)
Regards,
Arno Brinkman
ABVisie
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/
Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com
Nederlandse firebird nieuwsgroep :
news://80.126.130.81