Subject | RE: [firebird-support] 1 a n relationship with GROUP BY conditioned on master - Email found in subject |
---|---|
Author | Leyne, Sean |
Post date | 2011-12-07T17:50:07Z |
Fabio,
B2
SUM(B3)
FROM
B
JOIN A ON A1 = B1
WHERE
A2 = :Target
GROUP BY 1
OR
SELECT
B2
SUM(B3)
FROM (
SELECT A1
FROM A
WHERE
A2 = :Target
) T
JOIN B ON B1 = T.A1
GROUP BY 1
> I have 2 tablesSELECT
> A
> fields a1, a2, a3
>
> B
> Fields b1 ,b2, b3, b4
>
> I need to create a SQL retrieve sum(b3) and aggregate on b2 and filter on a2
> where a1=b1
B2
SUM(B3)
FROM
B
JOIN A ON A1 = B1
WHERE
A2 = :Target
GROUP BY 1
OR
SELECT
B2
SUM(B3)
FROM (
SELECT A1
FROM A
WHERE
A2 = :Target
) T
JOIN B ON B1 = T.A1
GROUP BY 1