Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: SQL help needed
Try to use this query in your view:
SELECT t1.CustNo, "Jan97", "Feb97", ...
FROM tbl t1, (SELECT CustNo, SUM(Amount) "Jan97" FROM tbl WHERE
TRUNC(Day) BETWEEN '01-Jan-97' AND '31-Jan-97' GROUP BY CustNo) t2,
(SELECT CustNo, SUM(Amount) "Feb97" FROM tbl WHERE TRUNC(Day) BETWEEN
'01-Feb-97' AND '28-Feb-97' GROUP BY CustNo) t3,.....
WHERE t1.CustNo=t2.CustNo
AND t1.CustNo=t3.CustNo
........
Hope this helps.
Michael Serbanescu
>Given the following table (customers with payment on a certain day)
>
> CREATE TABLE tbl
> (
> CustNo NUMBER,
> Day DATE,
> Amount NUMBER
> )
>
>Is it then possible to create a view, which shows ...
>
> - vertically: the customers
> - horizontal: the sum of the amounts for one month
>
>So one row should give one customer with 12 fields 'Jan97', 'Feb97', ...
>giving the totaled amount for that month.
>
>Michael G. Schneider
>
>mgs_software_at_compuserve.com
Received on Mon Nov 03 1997 - 00:00:00 CST