Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL-puzzle

Re: SQL-puzzle

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Fri, 04 Dec 1998 03:40:41 GMT
Message-ID: <3669588f.2868314@192.86.155.100>


A copy of this was sent to "Steinar Nyberg" <sn2_at_storebrand.no> (if that email address didn't require changing) On 3 Dec 1998 10:36:00 GMT, you wrote:

>I have to tables.
>
>Table Totals :
>week_num, product_num, service_num, solved_num
>
>This table allready contains the total number of cases called in to the
>help-desk for a all combinations of products and services for each week.
>The column solved_num is empty
>
>
>Table Case :
>opened_dat, product_num, service_num, solved_bln
>
>This table contains one row for each case called in to the help-desk.
>
>
>
>
>My problem :
>For each week I want to count the number of solved cases for each
>combination of product and service (from the Case-table).
>This result I'll insert in the Totals-table, in the correct row (the
>product+ service combination must correspond to prod. + service from the
>Case-table)
>

sounds more like you want to update not insert. If so:

update tableTotals

   set solved_num = ( select count(*)

                        from tableCase
                       where tableCase.product_num = tableTotals.product_num
                         and tableCase.service_num = tableTotals.service_num
                         and to_number(to_char(tableCase.opened_dat,'IW')) = 
                                          tableTotals.week_num )
/

that will take each row in the tableTotals table and run a query for it, that query will find for that product_num and service_num the count of rows in tableCase for the given week....

>How do I solve this problem, using a single SQL-string ?
>
>
>Thank you !
>
>
>Steinar
 

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA

--
http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Thu Dec 03 1998 - 21:40:41 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US