Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: A tricky SQL statement
> <anders.hattestad_at_vegdir.vegvesen.no> wrote:
>
> >I have a table that looks like this:
> >sident mident dato m00
> >M201 B1 07-16-95 2983
> >M201 B2 07-16-95 2996
> >M201 L1 07-16-95 2956
> >M201 RF 07-16-95 3
> >M201 VH 07-16-95 1
> >M201 VR 07-16-95 33
> >M251 B1 11-22-93 2555
> >M251 L1 11-22-93 2535
> >M251 RF 11-22-93 88
> >M251 VH 11-22-93 6
> >M251 VR 11-22-93 7
> >M253 B1 11-30-93 2658
Something like this should work (I haven't tested it)
SELECT
sident,
COUNT(DECODE(mident,'B1',mident,0)) "B1", COUNT(DECODE(mident,'B2',mident,0)) "B2", COUNT(DECODE(mident,'L1',mident,0)) "L1", COUNT(DECODE(mident,'RF',mident,0)) "RF"GROUP BY
>And I would like to extract it on this form:
>
>Sident B1 B2 L1 RF
>M201 2983 2996 2956 3
>M251 2535 88
>M253 2658
It would also be possible to build this query dynamically by finding out the unique values of ident and then building up the query from that.
Hope this helps,
regards,
paul