Help with SQL statements please.... URGENT PLEASE!!!!

I have 2 Tables
TABLE_NAME COLUMN_NAME DATA_TYPE
TASTEWINE TWDATE DATE
TASTEWINE BIN NUMBER
TASTEWINE QUANTITY NUMBER
TASTING TDATE DATE
TASTING PLACE VARCHAR2
a) Table TASTING has 2 columns.... TDATE( date Tasting was Held) and PLACE ( locations at which Tasting was held)
b) Table TASTEWINE has 3 Columns.............. TWDATE( wine tasting date, BIN( ID number for type of wine that was tasted), AND QUANTITY( quantity of win consumed by bottles)
Here is the QUestion.... I am having a hard time figuring out how to connect those two tables based on this information .. What I want to do is this.....select the total number of bottles of wine served at each wine-tasting, but only for the second half of the year 1999, and I want to see not only the date and total bottles served, but also the location where the wine-tasting took place. I also want to display the date, the place, and total quantity.
Can Anyone please Help me??

Hi,
Your query works fine - as well as the one mentioned by Alok. I have tired it with some sample values, and both show the same results:-
The two tables :-
CREATE TABLE TASTEWINE
     TWDATE     DATE,
     BIN     NUMBER,
     QUANTITY NUMBER
CREATE TABLE TASTING
     TDATE DATE,
     PLACE VARCHAR2(100)
);Rows in the Tables:-
INSERT INTO TASTEWINE VALUES (TO_DATE('01/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('02/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('03/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('04/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('05/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('06/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('07/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('08/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('09/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('10/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('11/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('12/12/1999','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('01/12/2000','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('02/12/2000','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('03/12/2000','MM/DD/YYYY'),1,100);
INSERT INTO TASTEWINE VALUES (TO_DATE('04/12/2000','MM/DD/YYYY'),1,100);
COMMIT;
INSERT INTO TASTING VALUES (TO_DATE('01/12/1999','MM/DD/YYYY'),'SEATTLE');
INSERT INTO TASTING VALUES (TO_DATE('02/12/1999','MM/DD/YYYY'),'SAN FRANSICO');
INSERT INTO TASTING VALUES (TO_DATE('03/12/1999','MM/DD/YYYY'),'DENVER');
INSERT INTO TASTING VALUES (TO_DATE('04/12/1999','MM/DD/YYYY'),'AUSTIN');
INSERT INTO TASTING VALUES (TO_DATE('05/12/1999','MM/DD/YYYY'),'SALT LAKE CITY');
INSERT INTO TASTING VALUES (TO_DATE('06/12/1999','MM/DD/YYYY'),'LOS ANGLES');
INSERT INTO TASTING VALUES (TO_DATE('07/12/1999','MM/DD/YYYY'),'PORTLAND');
INSERT INTO TASTING VALUES (TO_DATE('08/12/1999','MM/DD/YYYY'),'NEW YORK');
INSERT INTO TASTING VALUES (TO_DATE('09/12/1999','MM/DD/YYYY'),'NEWARK');
INSERT INTO TASTING VALUES (TO_DATE('10/12/1999','MM/DD/YYYY'),'EL PASO');
INSERT INTO TASTING VALUES (TO_DATE('11/12/1999','MM/DD/YYYY'),'AUSTIN');
INSERT INTO TASTING VALUES (TO_DATE('12/12/1999','MM/DD/YYYY'),'CHICAGO');
INSERT INTO TASTING VALUES (TO_DATE('01/12/2000','MM/DD/YYYY'),'ATLANTA');
INSERT INTO TASTING VALUES (TO_DATE('02/12/2000','MM/DD/YYYY'),'HOLLYWOOD');
INSERT INTO TASTING VALUES (TO_DATE('03/12/2000','MM/DD/YYYY'),'');
INSERT INTO TASTING VALUES (TO_DATE('04/12/2000','MM/DD/YYYY'),'SEATTLE');
COMMIT;The First Query :-
SELECT
     A.TWDATE,
     B.PLACE,
     SUM(A.QUANTITY)
FROM
     TASTEWINE     A,
     TASTING          B
WHERE
          A.TWDATE = B.TDATE
     AND     B.TDATE > TO_DATE('01/07/1999', 'DD/MM/YYYY')
     AND     B.TDATE < TO_DATE('01/01/2000', 'DD/MM/YYYY')
GROUP BY
     A.TWDATE,
     B.PLACE;The Second Query :-
SELECT
     A.TWDATE,
     B.PLACE,
     SUM(A.QUANTITY)
FROM
     TASTEWINE     A,
     TASTING          B
WHERE
          A.TWDATE = B.TDATE
     AND     B.TDATE
               BETWEEN
                    TO_DATE('01/07/1999', 'DD/MM/YYYY')      AND
                    TO_DATE('01/01/2000', 'DD/MM/YYYY')
GROUP BY
     A.TWDATE,
     B.PLACE;Regards,
Sandeep

Similar Messages

  • Problems with SQL statement ..Urgent Help required

    Hi
    I have a table with something like this
    ::: inidicates column seperation
    col1 ::: col2 ::: col3 ::: col4
    ab,abc,abvfg,fghy ::: x1 ::: y1 ::: z1
    ba,mkl,huji,kill ::: x2 ::: y2 ::: z2
    I want to get something like this :
    col1 ::: col2 ::: col3 ::: col4
    ab ::: x1 ::: y1 ::: z1
    abc ::: x1 ::: y1 ::: z1
    abvfg ::: x1 ::: y1 ::: z1
    fghy ::: x1 ::: y1 ::: z1
    and so on......
    Either a procedure or a single sql statement is fine..
    PS: the first column can have any number of words separated with comma (,)
    Please advise
    Thanks in advance

    create table kris (
    a varchar2(200),
    b varchar2(20),
    c varchar2(20),
    d varchar2(20));
    insert into kris values('ab,abc,abvfg,fghy', 'x1','y1','z1');
    insert into kris values('ba,mkl,huji,kill', 'x2','y2','z2');
    select substr(','||a||',', instr(','||a||',', ',', 1, rn) +1,
         instr(','||a||',', ',', 1, rn+1) - instr(','||a||',', ',', 1, rn) -1)
         v,b,c,d
    from (select length(a) - length(translate(a, '1,', '1')) +1 L,
         a, b, c, d from kris) t, (select rownum rn from cat) c
         where c.rn <= t.L
    order by a, rn;
    V B C D
    ab x1 y1 z1
    abc x1 y1 z1
    abvfg x1 y1 z1
    fghy x1 y1 z1
    ba x2 y2 z2
    mkl x2 y2 z2
    huji x2 y2 z2
    kill x2 y2 z2

  • Help with If statement please

    Hi,
    First Special thanks to Kglad for the help with the AS1 to AS3 conversion.
    I've been able to link up my buttons to play a different frames of the movie. this was my novice way of finally getting the programming to work.
    In frame 95 I have
    var myLoader:Loader = new Loader();
    addChild(myLoader); var url:URLRequest = new URLRequest("page1.swf");
    myLoader.load(url);
    in frame 165:
    var myLoader1:Loader = new Loader();
    addChild(myLoader1); var url1:URLRequest = new URLRequest("page1.swf");
    myLoader1.load(url1);
    My buttons link to 116 which plays a frame and loads ^
    in frame 226: removeChild(myLoader).
    But if the user has looped back into home from another part in the movie clip then it would need to remove myLoader1 instead of myLoader.
    I'm guessing there is some really dynamic way to solve the programatic nightmare i'm developing, but I'm really novice.
    So what i need is an if statement for frame 226
    That would do something:
    if(myLoader <> null
         removeChild(myLoader)
    else(
    removechild(myLoader1)
    Anyone have a method for this?

    yes, you can use the same urlrequest but just change its url property:
    // initialize, for example in frame 1.  this is done once and never again:
    var loader:Loader=new Loader();
    var urlR:URLRequest=new URLRequest();
    //  then in frame 2, for example:
    urlR.url="page1.swf";
    loader.load(urlR);
    //  in frame 20, for example:
    urlR.url="page2.swf";
    loader.load(urlR);
    // in frame 30, for example:
    urlR.url="page3.swf";
    loader.load(urlR);
    //etc.  if you're loading any swfs that play streams (sound or video), you'll want to add some code to this.

  • Help with sql statements and Java

    Hi,
    How can I create a string kind of like this
    Select * From Students Where Name Like "Bob Burns";
    As the sql statement might indicate I am using MS Access. I seem to be having problems with the double quotes required by the Like operator in MS Access, Java views that as a beginning of a string as oppposed to an actual string value.

    Like this:
        Connection connection = null;
        PreparedStatement stmt = null;
        ResultSet res = null;
        try  {
            connection = ...get from connection pool...;
            String sql = "select ... from ... where name like ?";
            stmt = connection.prepareStatement(sql);
            stmt.setObject(1, "%Bob%", java.sql.Types.VARCHAR);
            res = stmt.executeQuery();
            while (res.next()) { ...the usual...; }
        } finally {
            ...close res, stmt & return connection to pool...
        }You can try stmt.setString() instead of setObject() but rumor has it that some mssql drivers have a bug that makes setString() not work with "like", but oddly enough setObject() works.

  • Help with SQL statement in a coldfusion application

    I created 2 drop down list boxes one that contains the months
    and the second that contains the year. Right now my sql statement
    is Select * from job where releaseDate=#imageDate#. Now this was
    written in 2006 and I didn't know they were going to continue to
    use the tool in 2007. So now I need a sql statement that if a user
    selects Jan 2007 that all of jan 2007 will display. The format for
    the datetime field in the database is Jan 2 2007 hh:mm:ss the first
    box is named imageDate and the second is called StatusDate

    Take a look at the T-SQL datepart function.
    Bryan Ashcraft (remove BRAIN to reply)
    Web Application Developer
    Wright Medical Technology, Inc.
    Macromedia Certified Dreamweaver Developer
    Adobe Community Expert (DW) ::
    http://www.adobe.com/communities/experts/
    "rere" <[email protected]> wrote in message
    news:fjp4im$fqk$[email protected]..
    >I created 2 drop down list boxes one that contains the
    months and the
    >second
    > that contains the year. Right now my sql statement is
    Select * from job
    > where
    > releaseDate=#imageDate#. Now this was written in 2006
    and I didn't know
    > they
    > were going to continue to use the tool in 2007. So now I
    need a sql
    > statement
    > that if a user selects Jan 2007 that all of jan 2007
    will display. The
    > format
    > for the datetime field in the database is Jan 2 2007
    hh:mm:ss the first
    > box is
    > named imageDate and the second is called StatusDate
    >

  • Urgent help with If statement please!

    HI Everyone
    Was wondering if anyone can tell me why flash seems to be
    ignoring my If Statements, every time I try to use one it ignores
    the condition and just actions the command. Its driving me crazy.
    I'm sure I must be doing something wrong I just can't work it out.
    I've put;
    on (release) {
    if ((_root.eyeshadow = "Pink") && (_root.lipy =
    "Pink")) {
    _root.correct._alpha =100;
    It seems to just action the _root.correct._alpha = 100;
    even when a different colour is selected.
    I was wondering can flash read a variable from another
    script, because if not it will not know what eyeshadow and lipy
    are. I dont get any error messages though.
    Please help somebody!
    Thank you,
    Stacy.x.

    Thank you that appears to have made the if statement work,
    but now i have another problem.
    It doesn't seem to acknowledge wether these selections have
    been selected.
    I have put in the code for the pink eyeshadow;
    on (release) {
    _root.eyeshadow2._alpha =0;
    _root.eyeshadow1._alpha = 100;
    eyeshadow == "Pink";
    the same code is in all the other selections, with the name
    variations.
    any ideas?
    .x.

  • Need help with If statement Please

    Hi guys,
    This is my first time posting and sorry if for some reason i post incorrectly.
    I am having trouble figuring out what I am doing with my if Statement and why the compiler is giving me an error which says 'cannot find symbol';
    Just incase you need to see the code here it is. And please any pointers would help me get back on track. And please dont laugh at the novice code i just started^^;
    import java.util.*;
    import java.text.*;
    public class Student
         public static void main(String[]args)
         Scanner scan=new Scanner(System.in);
         double std1, std2, std3, num1, num2, num3, num4;
         String a, answer1, name1;
    System.out.println("Welcome to _____ program, press any button to continue: ")
    a=scan.nextLine();
    System.out.println("Good, would you like to enter a grade for a student(y/n)?");
    answer1=scan.nextLine();
    if (answer1 == y)
         System.out.println("Please enter the students name ");
                             name1=scan.nextLine();
                             System.out.println("Please label the test number ");
                             num1=scan.nextDouble();
                             System.out.println("Please enter the grade, "+name1+" recieved");
    std1=scan.nextDouble();
    if (answer1==n)
         System.out.println("Thank you for trying my program ");
    else
    System.out.println("It's obvious you couldn't follow a simple direction good bye ");

    Thanks Flounder,
    I'll keep in mind to edit the code the way you told me too.
    As far as the code goes, what do you mean 'y' is not a string and should be a variable. All I'm trying to do is give a true false statement.
    For example
    if (input==y)
    System.out.println("________");
    And in my code it gives an error stating that y is a variable.
    I dont understand why.
    Thanks much for all your replies.

  • What is Happening,help with these stats please

    Well I have checked my router system logs and for the second day,it looks like the router is disconecting to the exchange at the same time each day,and also if you look at the path it says "0",not interleave or fast,this has only started to happen,if this continues then I will end up with ip profile probs again
    Any ideas please.......just to add it is doing it at exactly the same time @ 05:42
    Jul 12 05:42:38  user  kernel: Line 0: ADSL link down  Jul 12 05:42:38  user  syslog: tc qdisc del dev ppp_0_0_38_1 root 2>/dev/null  Jul 12 05:42:40  daemon  pppd[458]: Terminating connection due to link down.  Jul 12 05:42:59  user  kernel: Line 0: xDSL G.994 training  Jul 12 05:43:08  user  kernel: Line 0: ADSL G.992 started  Jul 12 05:43:13  user  kernel: Line 0: ADSL G.992 channel analysis  Jul 12 05:43:19  user  kernel: Line 0: ADSL G.992 message exchange  Jul 12 05:43:20  user  kernel: Line 0: ADSL link down  Jul 12 05:43:25  user  kernel: Line 0: xDSL G.994 training  Jul 12 05:43:34  user  kernel: Line 0: ADSL G.992 started  Jul 12 05:43:38  user  kernel: Line 0: ADSL G.992 channel analysis  Jul 12 05:43:44  user  kernel: Line 0: ADSL link up, Path 0, us=864, ds=19208  Jul 12 05:43:46  daemon  pppd[458]: Clear IP addresses.  Connection DOWN. 

    Just to add,the speedtester results are still OK.
    Test1 comprises of two tests
    1. Best Effort Test:  -provides background information.
    Download  Speed
    14186 Kbps
    0 Kbps
    21000 Kbps
    Max Achievable Speed
     Download speedachieved during the test was - 14186 Kbps
     For your connection, the acceptable range of speeds is 4000-21000 Kbps.
     Additional Information:
     Your DSL Connection Rate :19208 Kbps(DOWN-STREAM), 864 Kbps(UP-STREAM)
     IP Profile for your line is - 16000 Kbps
    2. Upstream Test:  -provides background information.
    Upload Speed
    711 Kbps
    0 Kbps
    864 Kbps
    Max Achievable Speed
    >Upload speed achieved during the test was - 711 Kbps
     Additional Information:
     Upstream Rate IP profile on your line is - 864 Kbps

  • Help with SQL Script please

    Hi there,
    What I`m trying to accomplish here is the following guys;
    This would be the pseudo code that I`m trying to convert into proper SQL;
    Declare @Parameter varchar(50)
    now I`m trying to find out how to find whatever is in the @Parameter in the values of table column. something like this;
    If @Parameter exists in (select column from table) then do something here else something else....
    Thanks very much in advance for your help.

    do you want some thing like below
    Declare @Parameter varchar(50)
    If exists (select column from table where column = @Parameter)
    begin
    --do something here
    END
    else
    Begin
    --something
    END
    Thanks
    Saravana Kumar C

  • Help with access control please

    So I'm trying to set up my brother's PSP to the wirless network through MAC address timed access. What I want to do is make it so that he can only access it through certain times in the day. I'm having troubles with actually getting it to work. Everytime I set it up, the PSP only show's up as a DHCP client and not a Wireless client. I tried the option panel with the add wireless clients through the first try access. Could I get some help with this issue please? Thanks!

    Just to calm your fears... There is no conspiracy. If someone had an answer or a suggestion they would post it.

  • Need help on SQL Statement for UDF

    Hi,
    as I am not so familiar with SQL statements on currently selected values, I urgently need help.
    The scenario looks as follows:
    I have defined two UDFs named Subgroup1 and Subgroup2 which represent the subgroups dependent on my article groups. So for example: When the user selects article group "pianos", he only sees the specific subgroups like "new pianos" and "used pianos" in field "Subgroup1". After he has selected one of these specific values, he sees only the specific sub-subgroups in field "Subgroup2", like "used grand pianos".
    I have defined UDTs for both UDFs. The UDT for field "Subgroup1" has a UDF called "ArticleGroup" which represents the relation to the article group codes. The UDT for field "Subgroup2" has a UDF called "Subgroup1" which represents the relation to the subgroups one level higher.
    The SQL statement for the formatted search in field "Subgroup1" looks as follows:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP1]  T0 WHERE T0.[U_ArticleGroup]  = (SELECT $[OITM.ItmsGrpCod])
    It works fine.
    However, I cannot find the right statement for the formatted search in field "Subgroup2".
    Unfortunately this does NOT WORK:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2]  T0 WHERE T0.[U_Subgroup1]  = (SELECT $[OITM.U_Subgroup1])
    I tried a lot of others that didn't work either.
    Then I tried the following one:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2]  T0 WHERE T0.[U_Subgroup1] = (SELECT T1.[Code] FROM [dbo].[@B_SUBGROUP1] T1 WHERE T1.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod]))
    Unfortunately that only works as long as there is only one specific subgroup1 for the selected article group.
    I would be sooooo happy if there is anyone who can tell me the correct statement for my second UDF!
    Thanks so much in advance!!!!
    Edited by: Corinna Hochheim on Jan 18, 2010 10:16 PM
    Please ignore the "http://" in the above statements - it is certainly not part of my SQL.
    Please also ignore the strikes.

    Hello Dear,
    Use the below queries to get the values:
    Item Sub Group on the basis of Item Group
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP]  T0 WHERE T0.[U_GroupCod] =$[OITM.ItmsGrpCod]
    Item Sub Group 1 on the basis of item sub group
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP1]  T0 WHERE T0.[U_SubGrpCod]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP]  T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp])
    Sub group 2 on the basis of sub group 1
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP2]  T0 WHERE T0.[U_SubGrpCod1]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP1]  T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp1])
    this will help you.
    regards,
    Neetu

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • SQL STATEMENT , PLEASE HELP

    Hi,
    I want some help in writing a SQL Query .Its besically a hierarchical query. Let me lay down the table structure first to explain my requirements better.
    PORP_TABLE(NODE_LEVEL int, WBS_ID int, WBS_NUMBER varchar(60), LFT int,RGT int)
    SELECT NODE_LEVEL, WBS_ID, LFT,RGT FROM PROPOSAL_WBS PW WHERE PROPOSAL_REV_ID = 7000
    (SAMPLE DATA)
    NODE WBS
    LEVEL WBS_ID NUMBER LFT RGT
    0 7055 ROOT 1 24
    1 7056 1 2 5
    1 7088 2 6 9
    2 7057 1.1 3 4
    2 7089 2.1 7 8
    2 7091 3.1 11 14
    2 7103 3.2 15 16
    2 7105 4.1 19 20
    1 7090 3 10 17
    3 7092 3.1.1 12 13
    1 7104 4 18 23
    2 7106 4.2 21 22
    ALLOCATION_DETAIL( WBS_ID int, COST_ID int, PERIOD Date, AMOUNT Float)
    sample data
    WBS_ID , COST_ID , PERIOD , AMOUNT
    7057 100 01-jan-2005 5000
    7057 100 01-feb-2005 2000
    7057 100 01-mar-2005 1000
    7057 100 01-apr-2005 6000
    7057 100 01-may-2005 3000
    7057 100 01-jun-2005 45000
    7106 100 01-mar-2005 8000
    7106 100 01-apr-2005 7000
    7106 100 01-may-2005 9000
    Now the PORP_TABLE has got the parents and childs. Only the leaf nodes in the hierarchy has the values stored in the ALLOCATION_DETAIL table. Now here is the scenario
    In the example 7055 is the root WBS . The Leaf WBS are the one with max extension in the wbs number ( in this case it is 1.1, 2.1, 3.1.1, 3.2, 4.1 and 4.2)
    Now the Starting period for each leaf node in the ALLOCATION_TABLE could be differrent . What that means is WBS 1.1 could start in Jan -2003 and WBS 3.1 Could be Jul-2005 . So the ending perios are also differrent for differrent WBS . Some can span 2 years some can 5 years.
    So how to write a query so it retrieves the value for all the Wbs starting from the MIN ( PERIOD ) upto the MAX(PERIOD), and it should roll up also. Now there is No connect by Prior or any analytic functions available for this . THIS NEEDS TO BE DONE ONLY THROUGH TRADITIONAL SQL STATEMENT . And NO DB FUNCTIONS CAN BE USED .
    Now if the WBS is a parent node then it should have the sum of all its child nodes for the COST category.
    SO THE RESULT SET SHOULD BRING LIKE THIS
    WBS_NUMBER, PERIOD_NUMER, COST_CATEGORY , AMOUNT
    ROOT
    1
    1.1
    2
    2.1
    3
    3.1
    3.1.1
    3.2
    4
    4.1
    4.2
    ......

    Thanks for all your thoughtfull replies and feedbacks. Yes it is in Sybase platform . Though I have been woking all along in Oracle , Unfortunately this one is in Sybase, and no the customer cant and wont move to Oracle. So I have to work with it . And if you want to see the table structure . Here are they :
    CREATE TABLE PROPOSAL_WBS (
    BURDEN_CENTER_ID      numeric(18,0) NULL,
    START_DATE      datetime NULL,
    END_DATE      datetime NULL,
    WBS_ID      int NOT NULL,
    MODIFIED_DATE      datetime NULL,
    CREATED_DATE      datetime NULL,
    MODIFIED_BY      varchar(127) NULL,
    CREATED_BY      varchar(127) NULL,
    FEE_PERCENT      float NULL,
    PROPOSAL_REV_ID      int NOT NULL,
    PARENT_WBS_ID      int NULL,
    NAME      varchar(127) NULL,
    COMMENT      varchar(255) NULL,
    TARGET_COST      float NULL,
    MONTHS_REMAINING      int NULL,
    DEFAULT_STAFF_FTE      float NULL,
    ANNUAL_GRA_SALARY      float NULL,
    NUMBER_OF_GRA      int NULL,
    MANAGEMENT_ADJUSTMENT_TOTAL     float NULL,
    MA_UNALLOCATED_FUNDS      float NULL,
    FEE_TOTAL      float NULL,
    FEE_UNALLOCATED_FUNDS      float NULL,
    TRAVEL_COMMENTS      varchar(255) NULL,
    ODC_COMMENTS      varchar(255) NULL,
    SORT_ORDER      int NULL,
    LFT      int NULL,
    RGT      int NULL,
    NODE_LEVEL      int NULL,
    WBS_NUMBER      varchar(50) NOT NULL,
    TOTAL_COST      float NULL,
    TOTAL_COST_PLUS_FEE      float NULL,
    PER_MILE_COST      float NULL,
    PER_DIEM      float NULL,
    TAX_RATE      float NULL,
    RENTAL_CAR_PER_DAY_COST      float NULL,
    TAXI_PER_TRIP_COST      float NULL,
    CONSTRAINT PK_PROPOSAL_WBS PRIMARY KEY(WBS_ID)
    CREATE TABLE PROPOSAL_WBS_ALLOC_DETAIL (
    WBS_ID      int NOT NULL,
    OBJECT_CODE_ID      numeric(18,0) NOT NULL,
    PERIOD_NUMBER      int NOT NULL,
    ALLOCATION_AMOUNT     float NULL,
    PERIOD_YEAR      datetime NULL,
    CONSTRAINT PK_PROPOSAL_WBS_AD PRIMARY KEY(WBS_ID,OBJECT_CODE_ID,PERIOD_NUMBER)
    CREATE TABLE WBS_PERIOD (
    PERIOD_NUMBER     int NOT NULL
    CREATE VIEW WBS_COST_CAT AS
    SELECT PROPOSAL_WBS.PROPOSAL_REV_ID,
    PROPOSAL_WBS.WBS_ID,
    PROPOSAL_WBS.NAME, PROPOSAL_WBS.SORT_ORDER,
    PROPOSAL_WBS.NODE_LEVEL, PROPOSAL_WBS.WBS_NUMBER,
    CODES.CODE_ID COST_CATEGORY, CODES.CODE_NAME COST_CAT_NAME
    FROM PROPOSAL_WBS, CODES
    CREATE TABLE CODES (
    CODE_ID      numeric(18,0) NOT NULL,
    CODE_VALUE      varchar(254) NULL,
    CODE_NAME      varchar(254) NULL,
    CODE_TYPE      numeric(18,0) NULL,
    CODE_PARENT_ID     numeric(18,0) NULL,
    CONSTRAINT PK_CODE_ID PRIMARY KEY(CODE_ID)
    So let me explain little bit more . The WBSs are categorized into two differrent types. One as INPUT and the second one as NON INPUT. Now assme the the WBS in a tree structure . So only the LEAF WBSs will have the AMOUNT and they are the INPUT WBSs and all non leaf WBSs are NON INPUT. Now lets say there are 5 LEAF WBSs. Each LEAF WBS will have differrent start period ex: WBS 1.1 starts in January 2003 and goes for 48 periods . WBS 2.1 starts in November 2003 and goes for 35 periods . WBS 3.1 starts in March 2004 and goes for 52 periods. and so on .
    Now as there is no Allocation Amount entry for all other WBSs except the LEAF WBSs. So how do I get the roll up . For example if you imagine the parent of WBS 1.1 is WBS 1 , and the parent of WBS 2.1 is WBS 2 and the Parent of WBS 3.1 is WBS 3 , and the parent for WBS 1, WBS 2, WBS 3 is "ROOT WBS". As I said there is no entry for WBS 1, WBS 2 , WBS 3 and the "ROOT WBS". So how do I have a roll up of the Leaf WBS data for their parent WBSs.
    Now if u think of the data in a matrix report, the WBSs and the COST CATEGORY will be the row values, the Period Numbers will the column values and the Allocation Amount will be the cross values. so lets say the WBS 1 has got two leaf nodes, WBS 1.1 and WBS 1.2 then WBS 1 will have the summed amount for each period starting the minumum period of the two of its leaf nodes and for all the cost categories of both the leaf nodes. and the "ROOT WBS" will have all the cost categories of al the Leaf nodes . for all the periods , period wise.

  • Please help with SQL amount calulation

    -- Results
    with t as ( 
    select 'P11877' Mstr_Program,   1 Year_of_study, 'BUSI1490' program_module,  20 no_of_stud,    1 rank,   30 program_credits,  30 cumm_credits   from dual union all
    select 'P11877',                1,              'COMP1365',                 20,               2,        30,                  60               from dual union all
    select 'P11877',                1,              'BUSI1375',                 20,               3,        30,                  90               from dual union all
    select 'P11877',                1,              'COMP1363',                 20,               4,        30,                  120              from dual union all
    select 'P11877',                2,              'MARK1174',                 8,                1,        30,                  30               from dual union all
    select 'P11877',                2,              'FINA1068',                 8,                2,        15,                  45               from dual union all
    select 'P11877',                2,              'INDU1062',                 8,                3,        30,                  75               from dual union all
    select 'P11877',                2,              'BUSI1329',                 8,                4,        15,                  90               from dual union all
    select 'P11877',                2,              'MARK1138',                 8,                5,        30,                  120              from dual)
    select * from t;-- Each MSTR_PROGRAM can have 1 or many program_module
    -- MSTR_PROGRAM's can run for 1 or 2 years (case above is two years) so some modules run in year 1 and some in year 2
    -- NO_OF_STUD is the number of students on the module
    -- RANK basically ranks the modules by the number of students on them grouped by program and year
    -- e.g.row_number() OVER (PARTITION BY Mstr_Program, Year_of_study) ORDER BY COUNT(STUDENT_ID) DESC) rank
    -- PROGRAM_CREDITS: each module has a fixed number of credits
    -- CUMM_CREDITS: Increments the credit count of modules
    -- SUM(program_credits * 10) OVER (PARTITION BY Mstr_Program, Year_of_study
    -- ORDER BY count(STUDENT_ID) desc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
    -- I want to trim of any modules once the CUM_CREDITS hits 120. As seen above. I achieve this by wrapping the main query is another SELECT then LIMIT
    -- that WHERE cum_credit <=120.
    -- But what I need is:
    -- In some cases the the cumm_credit maybe on lets say 90credits then the next module is worth 40 credits. This next module will not show as it
    -- will be greater than 120 credits, so i need to pro-rata it:
    -- So if credit_count > 120, then the last module is counted pro-rata as follows: 1- ((credit count - 120) / credits from last module
    -- Can anyone help with how I can incorporate this into my current code: The SELECT portion of the Original SQL is below: I simplified column names
    -- e.t.c in the above so they wont be the same
    SELECT * FROM (
         SELECT
               ,SR_PROGRAM Mstr_Program
               ,DECODE (SORLCUR_YEAR, 1, 1,
                                      2, 2,
                                      3, 3,
                                      4, 3, SR_YEAR) year_of_study
               ,SCT_SUBJ_CODE||SCT_CRSE_NUMB program_module
               ,COUNT(student_ID)                    no_of_stud
               ,row_number() OVER (PARTITION BY sr_program,
                                            DECODE (sr_year, 1, 1,
                                                                  2, 2,
                                                                  3, 3,
                                                                  4, 3, SR_YEAR) ORDER BY COUNT(student_id) DESC, scbcrse_title asc) rank
               ,(SCT_CREDIT_HRS * 10) program_credits
               ,SUM(SCT_CREDIT_HRS * 10) OVER (PARTITION BY sr_program, DECODE (sorlcur_year, 1, 1,
                                                                                                       2, 2,
                                                                                                       3, 3,
                                                                                                       4, 3, SR_YEAR)
                                                    ORDER BY count(student_id) desc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
    WHERE cumm_credit <=120
    ORDER BY Mstr_Program, YEAR_OF_STUDY, RANK asc;

    Maybe
    SELECT Mstr_Program,year_of_study,program_module,no_of_stud,rank,program_credits old_program_credits,cumm_credits old_cumm_credits,
           case when cumm_credits > 120
                then program_credits - cumm_credits + 120
                else program_credits
           end new_program_credits,
           case when cumm_credits > 120
                then 120
                else cumm_credits
           end new_cumm_credits
      FROM (SELECT SR_PROGRAM Mstr_Program,
                   DECODE(SORLCUR_YEAR,1,1,2,2,3,3,4,3,SR_YEAR) year_of_study,
                   SCT_SUBJ_CODE||SCT_CRSE_NUMB program_module,
                   COUNT(student_ID) no_of_stud,
                   row_number() OVER (PARTITION BY sr_program,DECODE(sr_year,1,1,2,2,3,3,4,3,SR_YEAR)
                                          ORDER BY COUNT(student_id) DESC,scbcrse_title) rank,
                   10 * SCT_CREDIT_HRS program_credits,
                   10 * SUM(SCT_CREDIT_HRS) OVER (PARTITION BY sr_program,DECODE(sorlcur_year,1,1,2,2,3,3,4,3,SR_YEAR)
                                                      ORDER BY count(student_id) desc
                                                  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
    WHERE 0 <= case when cumm_credits > 120
                     then program_credits - cumm_credits + 120
                     else program_credits
                end
    ORDER BY Mstr_Program,YEAR_OF_STUDY,RANKRegards
    Etbin
    Edited by: Etbin on 16.12.2011 8:50
    with
    t as   /* simulating the result achieved */
    (select 'P11877' Mstr_Program,1 Year_of_study, 'BUSI1490' program_module,20 no_of_stud,1 rank,30 program_credits,30 cumm_credits from dual union all
    select 'P11877',             1,               'COMP1365',               20,           2,     40,                70              from dual union all
    select 'P11877',             1,               'BUSI1375',               20,           3,     30,                100             from dual union all
    select 'P11877',             1,               'COMP1363',               20,           4,     40,                140             from dual union all
    select 'P11877',             2,               'MARK1174',               8,            1,     30,                30              from dual union all
    select 'P11877',             2,               'FINA1068',               8,            2,     50,                80              from dual union all
    select 'P11877',             2,               'INDU1062',               8,            3,     30,                110             from dual union all
    select 'P11877',             2,               'BUSI1329',               8,            4,     50,                160             from dual union all
    select 'P11877',             2,               'MARK1138',               8,            5,     30,                190             from dual
    select Mstr_Program,Year_of_study,program_module,no_of_stud,rank,program_credits old_credits,cumm_credits old_cumm,
           case when cumm_credits > 120
                then program_credits - cumm_credits + 120
                else program_credits
           end new_program_credits,
           case when cumm_credits > 120
                then 120
                else cumm_credits
           end new_cumm_credits
      from t
    where 0 <= case when cumm_credits > 120
                     then program_credits - cumm_credits + 120
                     else program_credits
                end

  • Help with photo albums Please

    Hi, i really need some help with my pictures, I've only got a very basic understanding of how my phone works and have somehow put a load of albums on my phone when i plugged it into the computer-I want to delete some of them off the phone but cannot work out how to do it, when i plug my phone in i can find the photo tab but cannot actually see the pictures and can't see any delete button!!! Please can someone help me, basic explanations would be gratefully recieved xxxx

    The photo sync is one way: computer to phone. To remove photos, synced to your phone, remove the check marks next to the albums/folders under the photos tab in itunes & hit the apply/sync button. They will be removed from your phone. You cannot delete photos that were synced to your phone, directly on your phone. The easiest way to manage photos synced to your phone is to create albums or folders on your computer. Move whatever photos you want on your phone into these albums/folders & then select them under the photos tab in itunes to sync to your phone. You can then remove or add photos to these various albums/folders on your computer & the itunes sync process will update your phone every time you sync.

Maybe you are looking for

  • New Macbook pro won't connect to older external hard drive

    My old MacBook suddently died after seven years. It contained a lot of data that I had backed up on an external hard drive using TimeMachine and transferring files to it. When I hooked it up to my new MacBook Pro (released mid-2012 I think), I couldn

  • I don't know what's wrong with iPad

    My ipad is going crazy. It's been typing on it's own, zooming and opening pages. Battery drains when I try to charge. I see many people have this same problem. Can't use ipad at all. Please help

  • Paths panel Display text

    I recently noticed a behavior difference between CS6 and CC that I don't really care for. I just want to point it out and see if may be there could be another option in the panel preferences to bring back the old behavior. In CS6 when you designated

  • Query Variable Help

    Dear Gurus, I was looking for a variable for Fiscal Year/Period in Busines content that can be a single entry, mandatory. I found one 0S_FPER. In the report, when I restrict Fiscal Year/Period with this variable, I wanted to select the 'offset' to -1

  • How do you change the Number of Plots Shown property of a Waveform Chart at runtime?

    Is there any possible way to change the Number of Plots Shown property of a Waveform Chart at runtime?  Thy Dynamic Stackplots example is way to limited.....