Subject | Re: [ib-support] SQL Question |
---|---|
Author | Arno Brinkman |
Post date | 2003-02-25T07:49:50Z |
Hi Michael,
are there just 2 records inside the table ?
For 2 records :
SELECT
(SELECT Sale FROM TableX WHERE LType = 0) AS Sale_0,
(SELECT DB FROM TableX WHERE LType = 0) AS DB_0,
(SELECT Sale FROM TableX WHERE LType = 1) AS Sale_1,
(SELECT DB FROM TableX WHERE LType = 1) AS DB_1
FROM
RDB$DATABASE
With a relation
SELECT
(SELECT Sale FROM TableX t2
WHERE LType = 0 and t2.LinkField = t1.LinkField) AS Sale_0,
(SELECT DB FROM TableX t2
WHERE LType = 0 and t2.LinkField = t1.LinkField) AS DB_0,
(SELECT Sale FROM TableX t2
WHERE LType = 1 and t2.LinkField = t1.LinkField) AS Sale_1,
(SELECT DB FROM TableX t2
WHERE LType = 1 and t2.LinkField = t1.LinkField) AS DB_1
FROM
TableX t1
GROUP BY
LinkField
I hope this helps.
Regards,
Arno Brinkman
> I have a table with a 3 fields in.Is there a relation between the two records where LType = 0 and LType = 1 or
> These are LType, Sale og DB.
> LType is either 0 or 1.
>
> I would like to make a select that returns this at each line:
>
> Sale (where LType=0), DB (Where LType=0), Sale (Where LType=1) and DB
> (Where
> LTYpe=1)
>
> Can I do this ?
>
> MAybe with a view ?
>
> My customer would like to have these numbers on the same line to make
> some
> compares.
are there just 2 records inside the table ?
For 2 records :
SELECT
(SELECT Sale FROM TableX WHERE LType = 0) AS Sale_0,
(SELECT DB FROM TableX WHERE LType = 0) AS DB_0,
(SELECT Sale FROM TableX WHERE LType = 1) AS Sale_1,
(SELECT DB FROM TableX WHERE LType = 1) AS DB_1
FROM
RDB$DATABASE
With a relation
SELECT
(SELECT Sale FROM TableX t2
WHERE LType = 0 and t2.LinkField = t1.LinkField) AS Sale_0,
(SELECT DB FROM TableX t2
WHERE LType = 0 and t2.LinkField = t1.LinkField) AS DB_0,
(SELECT Sale FROM TableX t2
WHERE LType = 1 and t2.LinkField = t1.LinkField) AS Sale_1,
(SELECT DB FROM TableX t2
WHERE LType = 1 and t2.LinkField = t1.LinkField) AS DB_1
FROM
TableX t1
GROUP BY
LinkField
I hope this helps.
Regards,
Arno Brinkman