Query help : Query to get values SYSDATE-1 18:00 hrs to SYSDATE 08:00 hrs

Hi Team
I want the SQl query to get the data for the following comparison : -
Order Created is a Date Column , and i want to find out all the values from (SYSDATE-1) 18:00 hours to SYSDATE 08:00 hours
i.e.
(SYSDATE-1) 18:00:00 < Order.Created < SYSDATE 08:00:00.
Regards

Hi, Rohit,
942281 wrote:
If i want the data in the below way i.e.
from (SYSDATE-1) 18:00 hours to SYSDATE 17:59 hours ---> (SYSDATE-1) 18:00:00 < Order.Created < SYSDATE 07:59:00.If you want to include rows from exactly 18:00:00 yesterday (but no earlier), and exclude rows from exatly 08:00:00 today (or later), then use:
WHERE   ord_dtl.submit_dt  >= TRUNC (SYSDATE) - (6 / 24)
AND     ord_dtl.submit_dt  <  TRUNC (SYSDATE) + (8 / 24)
So can i use the below format : -
ord_dtl.submit_dt BETWEEN trunc(sysdate)-(6/24) and trunc(sysdate)+(7.59/24) . Please suggest . .59 hours is .59 * 60 * 60 = 2124 seconds (or .59 * 60 = 35.4 minutes), so the last time included in the range above is 07:35:24, not 07:59:59.
If you really, really want to use BETWEEN (which includes both end points), then you could do it with date arithmentic:
WHERE   ord_dtl.submit_dt  BETWEEN  TRUNC (SYSDATE) - (6 / 24)
                  AND         TRUNC (SYSDATE) + (8 / 24)
                                           - (1 / (24 * 60 * 60))but it would be simpler and less error prone to use INTERVALs, as Karthick suggested earlier:
WHERE   ord_dtl.submit_dt  BETWEEN  TRUNC (SYSDATE) - INTERVAL '6' HOUR
                  AND         TRUNC (SYSDATE) + INTERVAL '8' HOUR
                                           - INTERVAL '1' SECONDEdited by: Frank Kulash on Apr 17, 2013 9:36 AM
Edited by: Frank Kulash on Apr 17, 2013 11:56 AM
Changed "- (8 /24)" to "+ (8 /24)" in first code fragment (after Blushadown, below)

Similar Messages

  • Query help: query to return column that represents multiple rows

    I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
    I need a query to find all names that occur in both of two separate locations.
    For example,
    bob usa
    bob mexico
    dot mexico
    dot europe
    hal usa
    hal europe
    sal usa
    sal mexico
    The query in question, if given the locations usa and mexico, would return bob and sal.
    Thanks for any help or advice,
    -=beeky

    How about this?
    SELECT  NAME
    FROM    <LOCATIONS_TABLE>
    WHERE   LOCATION IN ('usa','mexico')
    GROUP BY NAME
    HAVING COUNT(DISTINCT LOCATION) >= 2Results:
    SQL> WITH person_locations AS
      2  (
      3          SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      4          SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      5          SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      6          SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      7          SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      8          SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      9          SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
    10          SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
    11  )
    12  SELECT  NAME
    13  FROM    person_locations
    14  WHERE   LOCATION IN ('USA','Mexico')
    15  GROUP BY NAME
    16  HAVING COUNT(DISTINCT LOCATION) >= 2
    17  /
    NAM
    bob
    salHTH!
    Edited by: Centinul on Oct 15, 2009 2:25 PM
    Added sample results.

  • Help needed in getting values from the dynamically created text boxes

    Hello,
    I am developing one jsp page using struts. In the page i m
    dynamically adding some rows with two text boxes in each row. and after entering data into
    those textboxes , user clicks on save button and page is submitted.
    I want to capture all this data of dynamically added
    rows so that i can enter those rows into DB.
    how can i acheive this using struts?.
    Have anyone had tried doing it?. Please help.
    Thanx in advance
    Deepali Naik

    Hi,
    1. If you give these textBoxes the same name, then in your action you can call request.getParameterValues(paramName) - it returns String[ ] of values.
    2. You can give form textBox names like "name"+index or something like this in <logic:iterate> tag
    Good luck!

  • PLZ Help: how to get value of a request scoped Bean/Attribute in JSF ?!!!

    hi,
    I noticed this part of code to retrieve session scoped beans/vars in an ActionListener or other jsf classes, but it does not work for request scoped beans/vars :( what's the problem then ? what shall i do ?
    Type var = (Type)Util.getValueBinding("myBeanInRequest")).getValue(context);
    I have also set that getPhaseId() returns UPDATE_MODEL_VALUES or APPLY_REQUEST_VALUES.
    Any comment or idea ?

    I have declared my Bean in my JSP page not in the
    faces-config.xml. Does this make any problem ? Also I
    have tried the way you told me as well, but still the
    returned attribute is null.
    P.S. My bean is declared in my JSP page this way:
    <jsp:useBean id="newSurveyVar" class="SurveyModel"
    scope="request" />
    This declaration causes the SurveyModel instance to be created in request scope when the page is rendered, but that doesn't help you when the form is submitted -- that is going to happen on the next request (so the request attribute created here goes away). Basically, <jsp:useBean> is not typically going to be useful for request scope attributes (it's ok for session or application scope, though).
    and further I have this jsf code:
    <h:command_button label="Create" commandName="create"
    action="create" >
    <f:action_listener
    r type="CreateNewSurveyActionListener"/>
    </h:command_button>
    and this is my
    CreateNewSurveyActionListener.processAction(ActionEvent
    e) {
    if (actionCommand.equals("create_the_survey")) {
    FacesContext context =
    t = FacesContext.getCurrentInstance();
    SurveyModel survey =
    y =
    (SurveyModel)(Util.getValueBinding("newSurveyVar")).get
    alue(context);
    if (survey==null) // returns true :(((
    And since I've declared my beans here there is nothing
    special declared in my faces-config.xml
    For me again it is really strange why it is not
    working !!!
    Any idea ? Because the event listener is fired in a separate request, so the one you created in the page is gone.
    This is why the managed bean creation facility was created. If your component contains a valueRef that points at the bean name (or you evaluate a ValueBinding as illustrated earlier in the responses to your question), then the bean will get instantiated during the processing of the form submit.
    Craig McClanahan

  • Need help with LikeFilter for querying the keyset instead of value

    Hi,
    I'm looking for help with the LikeFilter.
    I need to query the cache to get all entries with key starting with a particular string.
    I could see samples using LikeFilter for querying the values in the cache but not the keyset.
    Can someone help?
    E.g:
    Cache Entries:
    abc123 - value1
    abc234 - value2
    bcd123 - value3
    I want to get all entries with key starting with 'abc'.
    thanks,
    rama.

    NJ, thanks for the quick reply.
    I tried something similar (as below) but this code gives me 'java.lang.NoClassDefFoundError: com/tangosol/util/ValueExtractor'.
    KeyExtractor extractor = new KeyExtractor("getKey");
    Filter filter = new LikeFilter(extractor, id+":%",'-',false);
    -rama.
    Edited by: 911950 on Feb 2, 2012 1:18 PM

  • MDX query Help - filtering Measures based on values in a dimension.

    Hi,
    I want to get values of a aggregate measure filtered by value available in Dimension attribute.
    Details:
    We have a Measure called "Average Compliance" which provides an average value over certain dimensions. Now I have some target values available for different attributes.
    Fact Table (there are bunch of other columns in the fact table)
    Id
    TargetId
    InstanceId
    LocationId
    Compliance
    1
    1
    1
    1
    0
    2
    1
    1
    2
    1
    3
    2
    1
    1
    1
    4
    2
    2
    1
    0
    5
    2
    1
    1
    1
    6
    2
    1
    1
    1
    Dimension
    TargetId
    Target Average Compliance
    1
    90
    2
    70
    3
    92
    4
    40
    Now I want to get a query where I can get the "Average Compliance" which is higher then the target average compliance.
    Is this achievable?
    Thanks in advance.

    HI,
    I did give this a try. (replacing the date dimensions.)
    WITH MEMBERMEASURES.mycalc AS
    [Dim Measure].[Target].
    CURRENTMEMBER.MEMBER_KEY
    SELECT
    {[Measures].[Average Compliance],MEASURES.mycalc}
    ON0
    FILTER([Dim Measure].[Target].[Target]
    ,([Measures].[Average Compliance] * 100) <
    --80
    CINT([Dim Measure].[Target].
    CURRENTMEMBER.MEMBER_KEY)
    )*[Dim Measure].[Measure Uri].[Measure Uri]
    ON1
    I am still seeing values for average compliance which are more than the target (I even tried setting the value to be hardcoded to 80 and I still see average compliance of 100
    Thanks

  • Query to get value sets associated with its descriptive flexfield

    Hi All,
    Here i have a issue
    I am trying to get Value sets associated with its descriptive flex field of Receivable application and
    also if i want this for particular responsibility i.e., GW RBC Receivable Super User.
    I hope u got it.
    Please suggest me some query to get this.
    This is very important for me.

    Hi, I think your question should be addressed to the OEBS experts

  • Bex query question:How to get total value ?

    For material level we can get value(quantityamount), but for the result is total quantitytotal amount, the result is wrong. How to get the total value correctly?
    I checked some material.which need coding. but I want to know if I can get easier way for that.
    Thanks.

    hi, i jus tried. .this works for me..
    set calculate result as summation and formula collision nothing defined...
    *reward if helpful*

  • A sum and case query help

    I need help please with the following query.
    I have a table that contains a currency, voucher, start_date and a value.
    Data in the tables looks like this:
    GB, 31/05/2010, A, 100
    GB, 31/05/2010, B, 250
    GB, 31/05/2010, A, 72
    GB, 12/12/2009, A, 1000
    GB, 12/12/2009, B, 72
    LX, 12/05/2010, A, 90
    This is where it gets complicated, I need to show the total(SUM) value when the start_date < 60 days from sysdate and also when the start_date > 61 days AND only if the voucher = A and partioned by the currency.
    So, in other words I need my results like this.
    GB, 31/05/2010, A, 100, *172, 0*
    GB, 31/05/2010, B, 250, *0, 0*
    GB, 31/05/2010, A, 72, *172, 0*
    GB, 12/12/2009, A, 1000, *0, 1000*
    GB, 12/12/2009, B, 72, *0, 0*
    LX, 12/05/2010, A, 90, *90, 0*
    The bold columns are what I need, one called less_than and one more_than.
    A big big thank you and any advice I appreciate.
    S

    Please make a habit of posting sample data we can work with right away by using CREATE TABLE and INSERT INTO statements, or use the WITH clause as shown below:
    SQL> with t as ( -- generating sample data:
      2  select 'GB' currency, to_date('31/05/2010', 'dd/mm/yyyy') start_date, 'A' voucher, 100 value from dual union
      3  select 'GB', to_date('31/05/2010', 'dd/mm/yyyy'), 'B', 250 from dual union
      4  select 'GB', to_date('31/05/2010', 'dd/mm/yyyy'), 'A', 72 from dual union
      5  select 'GB', to_date('12/12/2009', 'dd/mm/yyyy'), 'A', 1000 from dual union
      6  select 'GB', to_date('12/12/2009', 'dd/mm/yyyy'), 'B', 72 from dual union
      7  select 'LX', to_date('12/05/2010', 'dd/mm/yyyy'), 'A', 90 from dual
      8  )
      9  --
    10  -- actual query:
    11  --
    12  select currency
    13  ,      start_date
    14  ,      voucher
    15  ,      value
    16  ,      sum(case
    17               when  trunc(sysdate-start_date)< 60
    18               and  voucher = 'A'
    19               then value
    20               else 0
    21             end) over (partition by currency, voucher, start_date) sum_val1
    22  ,      sum(case
    23               when trunc(sysdate-start_date)> 61
    24               and  voucher = 'A'
    25               then value
    26               else 0
    27             end) over (partition by currency, voucher, start_date) sum_val2
    28  from   t;
    CU START_DAT V      VALUE   SUM_VAL1   SUM_VAL2
    GB 12-DEC-09 A       1000          0       1000
    GB 31-MAY-10 A         72        172          0
    GB 31-MAY-10 A        100        172          0
    GB 12-DEC-09 B         72          0          0
    GB 31-MAY-10 B        250          0          0
    LX 12-MAY-10 A         90         90          0
    6 rows selected.

  • Query Help on RowNum

    Hi ,
    Please help me on this…
    Select * from EMP where Emp_Type in (1, 2 ) order by Emp_Type;
    the above query gives me the result like this
    Emp_Id Name Emp_Type
    100     asas     1
    101 dsds     1
    122     gfgf     1
    154     ytytyt     1
    125     uyuy     1
    153     reree     2
    154     ytytt     2
    600     trtrtr     2
    700 gfghf 2
    If I pass the Start with num 2 and give 3 as number of records to be displayed. I need to retrieve only the following rows..
    Emp_Id Name Emp_Type
    101 dsds     1
    122     gfgf     1
    154     ytytyt     1
    154     ytytt     2
    600     trtrtr     2
    700 gfghf 2
    If the Emp_Type was only one ie,
    Select * from EMP where Emp_Type in (1) order by Emp_Type;
    I know I can get it done by using TOP-N query method
    select * from
    (Select rownum RWnum ,A.* From
    (Select * from EMP where Emp_Type in (1) order by Emp_Type) A
    where rownum<=4)
    where RWnum>=2;
    but I am stuck up with doing for multiple Emp_Type..
    here the Emp_Type could be more than two values…
    Regards
    Ben Narendran

    Hi muthukumar S,dnikiforv,Vsugur
    Thanks a lot for the analytical function ROW_NUMBER().
    But still have some concern about the query you have given..
    Let me first run the inner query.
    SQL>
    SQL > Select e.*,row_number() over(partition by Emp_Type order by Emp_Type) rno from
    EMP e where Emp_Type in (1, 2 ) order by Emp_Type;
    EMP_ID NAME EMP_TYPE RNO
    154 aaa 1 1
    101 dsds 1 2
    122 gfgf 1 3
    125 aaa 1 4
    100 asas 1 5
    700 gfghf 2 1
    600 trtrtr 2 2
    153 reree 2 3
    If I give the range from 2 and 3 am suppose to get the following rows.
    EMP_ID NAME EMP_TYPE RNO
    101 dsds 1 2
    122 gfgf 1 3
    600 trtrtr 2 2
    153 reree 2 3
    when I run the query you sent am getting the following result..
    SQL > select * from
    (Select e.*,row_number() over(partition by Emp_Type order by Emp_Type) rno from
    EMP e where Emp_Type in (1, 2 ) order by Emp_Type)
    where rno between 2 and 3;
    EMP_ID NAME EMP_TYPE RNO
    101 dsds 1 2
    154 aaa 1 3
    600 trtrtr 2 2
    700 gfghf 2 3
    Here the company id 700 is not suppose to come, instead I have to get 153.
    So I made some changes in the view and , wrote it like this
    SQL> select * from
    (select rno Rwnum,Outer_Qry.* from
    (select Real_Qry.*,row_number() over(partition by emp_type order by emp_type)rno
    from
    (select emp_id,name,emp_type from emp where emp_type in (1,2) order by emp_type)Real_Qry)Outer_Qry
    where rno <=3)
    where Rwnum >=2;
    RWNUM EMP_ID NAME EMP_TYPE RNO
    2 101 dsds 1 2
    3 122 gfgf 1 3
    2 600 trtrtr 2 2
    3 153 reree 2 3
    I guess now am getting the correct result..
    Please correct me if I am wrong, and please let me know if I have to make any modification on it..
    Thanks and regards
    Ben

  • Query Help required

    HI Experts ,
    Could you please help me in getting below output ,
    My Input Table :
    Number
    Loc_A
    LOC_B
    PARENT_NUMBER
    A-01
    Ind
    Aus
    A
    A-02
    Fra
    NZ
    A
    A-03
    Ind
    SL
    A
    A-04
    USA
    Aus
    A
    A-05
    Pak
    WI
    A
    A-06
    Fra
    Ag
    A
    A-07
    Rus
    Ban
    A
    A-08
    SA
    Ind
    A
    A-09
    Ind
    Ind
    A
    My Required Output
    Number
    Loc_A
    LOC_B
    PARENT_NUMBER
    A-01
    Ind
    Aus
    A
    A-02
    Fra
    NZ
    A
    A-03
    Ind
    SL
    null
    A-04
    USA
    Aus
    null
    A-05
    Pak
    WI
    A
    A-06
    Fra
    Ag
    null
    A-07
    Rus
    Ban
    A
    A-08
    SA
    Ind
    A
    A-09
    Ind
    Ind
    null
    I am comparing each and every record with its previous rows values for column Loc_A and Loc_B and if they are getting matched i m inserting null .
    table structure
    with t as
    (select 'A-01' as Num,'Ind' as Loc_A,'Aus' as Loc_B,'A' as Parent_Num from dual
    union all
    select 'A-02' as Num,'Fra' as Loc_A,'NZ' as Loc_B,'A' as Parent_Num from dual
    Union all
    select 'A-03' as Num,'Ind' as Loc_A,'SL' as Loc_B,'A' as Parent_Num from dual
    union all
    select 'A-04' as Num,'USA' as Loc_A,'Aus' as Loc_B,'A' as Parent_Num from dual
    union all
    select 'A-05' as Num,'Pak' as Loc_A,'WI' as Loc_B,'A' as Parent_Num from dual
    union all
    select 'A-06' as Num,'Fra' as Loc_A,'Ag' as Loc_B,'A' as Parent_Num from dual
    union all
    select 'A-07' as Num,'Rus' as Loc_A,'Ban' as Loc_B,'A' as Parent_Num from dual
    union all
    select 'A-08' as Num,'SA' as Loc_A,'Ind' as Loc_B,'A' as Parent_Num from dual
    union all
    select 'A-09' as Num,'Ind' as Loc_A,'Ind' as Loc_B,'A' as Parent_Num from dual
    select * from t;
    Could you please help ,i have 1000's of rows with this kind of data

    Hi,
    I have tried to create a query, this might help you
    WITH t AS (SELECT 'A-01' AS Num,
                      'Ind' AS Loc_A,
                      'Aus' AS Loc_B,
                      'A' AS Parent_Num
                 FROM DUAL
               UNION ALL
               SELECT 'A-02' AS Num,
                      'Fra' AS Loc_A,
                      'NZ' AS Loc_B,
                      'A' AS Parent_Num
                 FROM DUAL
               UNION ALL
               SELECT 'A-03' AS Num,
                      'Ind' AS Loc_A,
                      'SL' AS Loc_B,
                      'A' AS Parent_Num
                 FROM DUAL
               UNION ALL
               SELECT 'A-04' AS Num,
                      'USA' AS Loc_A,
                      'Aus' AS Loc_B,
                      'A' AS Parent_Num
                 FROM DUAL
               UNION ALL
               SELECT 'A-05' AS Num,
                      'Pak' AS Loc_A,
                      'WI' AS Loc_B,
                      'A' AS Parent_Num
                 FROM DUAL
               UNION ALL
               SELECT 'A-06' AS Num,
                      'Ind' AS Loc_A,
                      'Ag' AS Loc_B,
                      'A' AS Parent_Num
                 FROM DUAL
               UNION ALL
               SELECT 'A-07' AS Num,
                      'Rus' AS Loc_A,
                      'Ban' AS Loc_B,
                      'A' AS Parent_Num
                 FROM DUAL
               UNION ALL
               SELECT 'A-08' AS Num,
                      'SA' AS Loc_A,
                      'Ind' AS Loc_B,
                      'A' AS Parent_Num
                 FROM DUAL
               UNION ALL
               SELECT 'A-09' AS Num,
                      'Ind' AS Loc_A,
                      'Ind' AS Loc_B,
                      'A' AS Parent_Num
                 FROM DUAL)
    SELECT t.num,
           t.loc_a,
           t.loc_b,
           CASE
              WHEN (FIRST_VALUE (LOC_A)
                       OVER (ORDER BY NUM RANGE UNBOUNDED PRECEDING)) IN
                         (LOC_A, LOC_B)
                    OR (FIRST_VALUE (LOC_B)
                         OVER (ORDER BY NUM RANGE UNBOUNDED PRECEDING)) IN
                         (LOC_A, LOC_B)
              THEN
              ELSE
                 t.parent_num
           END
              parent_num
      FROM t
    NUM
    LOC_A
    LOC_B
    PARENT_NUM
    A-01
    Ind
    Aus
    A-02
    Fra
    NZ
    A
    A-03
    Ind
    SL
    A-04
    USA
    Aus
    A-05
    Pak
    WI
    A
    A-06
    Ind
    Ag
    A-07
    Rus
    Ban
    A
    A-08
    SA
    Ind
    A-09
    Ind
    Ind
    Only error I have here is the First Value is showing '-'. I have not got enough time to remove it.
    Regards,
    Adarsh

  • Result of the query is not filtered as value given in Select Option variabl

    Hello ,
    A Select option Variable is created on Navigational Attribute( ZINV_PROG) of 0WBS_ELEMT.
    The Compound Key for object ZINV_PROG(Investment program) is APPR_YEAR( Approval Year)
    This ZINV_PROG object does not bear Master data.
    The values in the field get populated as you load Master data of 0WBS_ELEMT.
    The values for this objects is as shown below:
    APPR_YEAR ZINVPROG
    2005 ESCCCAPS
    2007 ESCCCAPS
    2008 FIRE
    2006 CAPITAL
    A select option variable is craeted on this Navigational attribute.
    When you execute the query , On the selection screen of the query..
    If you provide i/p for Investment programm field as 2007 ESCCCAPS, the data should ideally be filtered for this values only.
    But the result of the query shows data for both values 2005 ESCCCAPS and as well as for 2007ESCCCAPS.
    Let me know how to sort this issue.
    Points will be assigned for the correct and helpfull answere.
    Thanks,

    Thanks Srini for your prompt explanation.
    My Question is if Approval year is a compounded key of ZINV_PROG object why data would not get filter out directly.
    I mean on the screen for this particualr variable i take help - F4 to see values there you are able to see all the values of Investment programm along with the apprroval year.
    If i select value as 2005 ESCCCAPS from the help F4 screen then ideally data should be fileterd out for this particular value. But it is not happening so.
    Is that so in Query desgining that if you creating a variable on Nav Attribute, and that particular Nav attribute has a compound key then if you want to filter out the data for this Nav attribute correctly you would also require to create a variable for Compound key also.
    Please let me know
    Thanks

  • SQL Query Help - Is this possible or impossible????

    Hi guys,
    I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
    For example,
    I have 2 tables
    The first table is:
    1) COMPANY create table company (manufacturer varchar2(25),
                                                          date_established date,
                                                          location varchar2(25) );My sample test date is:
    insert into company values ('Ford', 1902, 'USA');
    insert into company values ('BMW', 1910, 'Germany');
    insert into company values ('Tata', 1922, 'India');The second table is:
    2) MODELS create table models (manufacturer varchar(25),
                                                 model varchar2(25),
                                                 price number(10),
                                                 year date,
                                                 current_production_status varchar2(1) ) ;My sample test data is:
    insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
    insert into models values ('Ford', 'Galaxy', 12000,   2008, 0);
    insert into models values ('Ford', 'Escort', 10000, 1992, 1);
    insert into models values ('BMW', '318', 17500, 2010, 0);
    insert into models values ('BMW', '535d', 32000,   2006, 0);
    insert into models values ('BMW', 'Z4', 10000, 1992, 0);
    insert into models values ('Tata', 'Safari', 4000, 1999, 0);
    insert into models values ('Tata', 'Sumo', 5500,   1996, 1);
    insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer IN ('Ford', 'BMW', 'Tata')
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCWhat I want the query to output is this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               Sumo               5500               1998          1If current_production_status is 1 it means this particular model has been discontinued
    If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
    The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
    So the query should output the one row where current_production_status is 1 for each manufacturer.
    If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
    My query as it is above will output all the records where current status is 1 or 0 like this
    com.manufacturer        com.date_established          com.location          mod.model          mod.price          mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    Tata               1922                    India               Sumo               5500               1998          1
    Ford               1902                    USA               -               -               -          0                    
    Ford               1902                    USA               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               -               -               -          0
    Tata               1922                    India               -               -               -          0However this is not what I want.
    Any ideas how I can achieve the result I need?
    Thanks!
    P.S. Database version is '10.2.0.1.0'

    Hi Vishnu,
    Karthiks query helped...
    But this is the problem I am facing...
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer = 'Ford'
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCThe value of:
    and com.manufacturer = 'Ford'will be dependent on front end user input....
    When I run the query above I get all the rows where current_production_status is either 1 or 0.
    I only require the rows where current_production_status is 1.
    So if I amend it to look like this:
         and mod.current_production_status = 1This works....
    BUT if a user now passes in more than one manufacturer EG:
    and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
    So like this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
    Thanks you so much!
    This is really driving me insane :-(

  • Creating an SQL Query for Project Custom Fields Values

    Hello:
    I'm currently trying to create an SQL Query to show all of the server's Project Custom Fields Values, along with the modification date.
    So far, I've managed to display correctly all of the data for all of the Projects' text value Custom Fields (those not based on a LookUp Table) with this query:
    SELECT
    MSP_PROJECTS.PROJ_NAME,
    MSP_CUSTOM_FIELDS.MD_PROP_NAME,
    MSP_PROJ_CUSTOM_FIELD_VALUES.CODE_VALUE,
    MSP_PROJ_CUSTOM_FIELD_VALUES.TEXT_VALUE,
    MSP_PROJ_CUSTOM_FIELD_VALUES.MOD_DATE
    FROM
    MSP_PROJ_CUSTOM_FIELD_VALUES
    INNER JOIN
    MSP_CUSTOM_FIELDS
    ON MSP_CUSTOM_FIELDS.MD_PROP_UID = MSP_PROJ_CUSTOM_FIELD_VALUES.MD_PROP_UID
    INNER JOIN
    MSP_PROJECTS
    ON MSP_PROJECTS.PROJ_UID = MSP_PROJ_CUSTOM_FIELD_VALUES.PROJ_UID
    WHERE
    MSP_PROJ_CUSTOM_FIELD_VALUES.CODE_VALUE IS NULL
    ORDER BY
    MSP_PROJ_CUSTOM_FIELD_VALUES.PROJ_UID,
    MSP_PROJ_CUSTOM_FIELD_VALUES.MD_PROP_UID
    However, when I try a new Query to obtain the actual values for the Projects Custom Fields that do use a LookUp Table, I can't seem to find what table in the model I'm supposed to link to the MSP_PROJ_CUSTOM_FIELD_VALUES.CODE_VALUE field (the TEXT_VALUE
    field has NULL value when CODE_VALUE field isn't NULL)
    Any suggestions on how to obtain the actual Projects' custom fields values instead of the Code Value, for Metadata that do use a LookUp Table?
    Also, I'm able to run this query only in the Published Database, since the MSP_CUSTOM_FIELDS table is empy in the Draft Database. Why is that?
    Awaiting your kind reply,
    Sebastián Armas PMO Project Manager

    Hi Sebastián, rather than directly accessing the database it would be better to use the PSI to get this data.  Take a look at the ProjTool sample in the SDK whcih gets this data.
    Best regards,
    Brian.
    Blog |
    Facebook | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Project Server TechCenter |
    Project Developer Center |
    Project Server Help | Project Product Page

  • Bucket query help

    create table rangespendbucket(rangespend varchar2(40), id number)
    insert into rangespendbucket values('100-200',1);
    insert into rangespendbucket values('200-500',2);
    insert into rangespendbucket values('500-1000',3);
    insert into rangespendbucket values('1000-',4);
    commit;
    create table spend(supplier varchar2(40), cy_spend number)
    insert into spend values('A',100);
    insert into spend values('B',25);
    insert into spend values('C',30);
    insert into spend values('D',1000);
    insert into spend values('E',10);
    insert into spend values('A',200);
    insert into spend values('F',0);
    insert into spend values('E',20);
    insert into spend values('C',540);
    insert into spend values('B',300);
    insert into spend values('A',300);
    insert into spend values('C',10);
    insert into spend values('B',0);
    insert into spend values('E',0);
    insert into spend values('G',90);
    insert into spend values('H',0);
    insert into spend values('A',0);
    insert into spend values('P',7000);
    commit;
    i am new in this forums . some one in my company given me the following query/task.
    I want find out all those in a single query(1-8) except 1.1(separatee query).
    we are using oracke 10g reaalese 2 version.
    1)no of customer/supplier in the spend bucket.
    1.1. If anybody clcik on that particular bucket it will show no of suppliers.
    2)total no of supplier for all bucket(sum)
    3)% of supplier for each bucket.(each bucket supp cnt *100/total supp cnt)
    3)total spend for each bucket
    4)total spend for all combination of bucket
    5)% of spend for each bucket than total bucket(each bucket supp spend *100/total supp spend)
    6)how many no of suppliers make 80% of total spend(respect to all bucket)
    7)how many no of suppliers make 20% of total spend(respect to all bucket)
    8)top 3 suppliers make how much % of spend(respect to all bucket)
    i am eagerly requesting to all of you please help me to making this query.
    this query is required for making dashboard.
    column name should be like this-totalsupplierscnt__all_bucket,'cnt suppliers 100-200','%cnt suppliers 100-200','cnt supplier 200-500','%cnt supplier 200-500',
    'cnt supplier 500-1000','%cnt supplier 500-1000','cnt suppliers 1000-','%cnt suppliers 1000-',
    totalsuppliersspend_all_bucket,'spend for 100-200','%spend for 100-200','spend for 200-500','%spend for 200-500',
    'spend for 500-1000','%spend for 500-1000','spend for 1000-','%spend for 1000-',
    'no of supplierss 80% of total spend'(calculation-suppose total spend 100. spend sorted by decending 80% of total spend may cover 1-2 suppliers),
    'no of supplierss 20% of total spend'(calculation- total no of suppliers- no of suppliers making 80% spend),
    'top 3 suppliers spend'(calculation-spend sorted by desc,if we get total spend then we calculate -top3'spend*100/total spend)
    if you want much more clarification i will give you.
    Edited by: 949497 on Jul 27, 2012 7:51 PM
    Edited by: 949497 on Jul 27, 2012 8:11 PM

    Hi,
    Welcoem to the forum!
    949497 wrote:
    create table rangebucket(rangespend varchar2(40), id number) ...Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful!
    i am new in this forums ....You're way ahead of some people, who have been using the forum for years but still haven't learned how to post their data.
    Don't forget to post the exact results you want from that data.
    How are the two tables related? Do you have to parse rangebucket.rangespend to extract the NUMBERs 100 and 200 from the VARCHAR2 '100-200'? It would be simpler to do it the other way around: store the NUMBERs 100 and 200 in two separate NUMBER columns, and derive the label '100-200' from them (or store the label in a separate column, as it is now, in addition to rangebegin and rangeened NUMBER columns).
    Whatever number is related to these ranges, what happens if that number is exactly 200? What if it is less than 100?
    >
    I want find out all those in a single query(1-8) except 1.1(separatee query).
    we are using oracke 10g reaalese 2 version.Thanks! That's another thing that's always imoportant (and another thing some people haven't learned to do).
    1)no of customer/supplier in the spend bucket.
    1.1. If anybody clcik on that particular bucket it will show no of suppliers.This is the SQL and PL/SQL forum. What do you mean by "click", and how does it involve SQL or PL/SQL?
    2)total no of supplier for all bucket(sum)
    3)% of supplier for each bucket.(each bucket supp cnt *100/total supp cnt)
    3)total spend for each bucket
    4)total spend for all combination of bucket
    5)% of spend for each bucket than total bucket(each bucket supp spend *100/total supp spend)
    6)how many no of suppliers make 80% of total spend(respect to all bucket)I'm not certain I understand what any of the outputs are, but I'm especially unsure of 6) and 7).
    Do you want the smallest possible number of suppliers, such that their spend totals account for at least 80% of all spend total?
    Do you want the largest possible number of suppliers, such that their sepnd total just barely exceeds 80% of the overall total?
    Do you want something else entirely?
    When you post the results you want from the given sample data, explain this part very carefully.
    7)how many no of suppliers make 20% of total spend(respect to all bucket)
    8)top 3 suppliers make how much % of spend(respect to all bucket)I suspect you'll need to use aggregate functions to get the total by suppliers, and then use analytic fucntions to answer questions such as "Is the running total greater than 80% yet?". I'm sure this will be clearer after you post the results you want.

Maybe you are looking for

  • Cover Flow view bug

    Is there a better place than this to submit bug reports to Apple? Problem: Multiple albums named the same (i.e. Greatest Hits) by different artists have problems in Cover Flow view. The albums have separate cover art, but when selecting the album to

  • EOIO queue name change

    Hi All, any possibility EOIO queue name can be changed in Message mapping?? Thank You, Madhav

  • Asset accontdetermination

    hi experts        in asset accounting  i am geting error "account expense account for ordinary depreciation could not be found for area1" message au133 for this i checked in a090 for depreciation expenses account there  we assigned this account then

  • No document after download

    My Adobe Reader has not worked properly since I had some work done on my computer.  When I download a document the download bar appears on the screen and it appears that the download is complete but the document never appears on the screen.  I have t

  • Mindscape Babyz Game

    I originally downloaded some files that turned the sound off and gave a fresh baby. It worked for a week then all of a sudden stopped working. I am on Windows 7 but used the compatibility tool to let it play like it is on Windows 2000 (as was suggest