Query needed

Query to get list of employees having photo attached with their profile and query needed to extract the January to April timesheets approved in oracle on 6th May 2008

sorry could not understand your question completely.
I think following query should work, but I am not sure
select *
from hxc_time_building_blocks
where start_time >= sysdate - 60
and scope = 'APPLICATION_PERIOD'
and trunc(date_from) = trunc(sysdate)
and date_to = to_date('31-12-4712', 'DD-MM-YYYY')
and approval_status = 'APPROVED';
Change your date from sysdate to some other date. This query is not optimized so you need to tweak it a bit if it works at all.
Any other OTL Expert on this

Similar Messages

  • Defining more parameters than a query needs

    Hi.
    When I run the following code, I get the error "ORA-01036: illegal variable name/number" .
    The problem is that I currently define more parameters than the query needs. Thats because I don't know how many bind variables the query uses, and I would not like to parse the query ...
    I don't understand why I have to define exactly the same number of parameters, and in the exact order ... It doesn't make sense. As bind variables have names, there should be no problem passing more parameters or parameters in a different order: the binding should be done by name...
    I'm currently using Oracle10g, ODP.NET and .NET Framework 2.0.
    I would appreciate any help ...
    Thank you.
    Ricardo Coimbras
    ===== BEGIN VB.NET CODE =====
    Sub Execute_Query(ByVal SqlString as String)
    Dim ObjCmd As OracleCommand
    Dim DataAdap As OracleDataAdapter
    Dim outDsCorpo As DataSet
    Dim Constroi_Conn_String_Oracle As String
    Dim mObjConnOracle As OracleConnection
    Constroi_Conn_String_Oracle = "User ID=uuu" & _
    ";Password=ppp" & _
    ";Data Source=bd" & _
    ";Pooling=false"
    mObjConnOracle = New OracleConnection(Constroi_Conn_String_Oracle)
    mObjConnOracle.Open()
    ObjCmd = mObjConnOracle.CreateCommand()
    ObjCmd.CommandType = CommandType.Text
    ObjCmd.CommandText = SqlString
    ObjCmd.Parameters.Add("p1", OracleDbType.Char, 3, "001", ParameterDirection.Input)
    ObjCmd.Parameters.Add("p2", OracleDbType.Char, 3, "001", ParameterDirection.Input)
    DataAdap = New OracleDataAdapter(ObjCmd)
    outDsCorpo = New DataSet()
    DataAdap.Fill(outDsCorpo)
    GridView1.DataSource = outDsCorpo
    GridView1.DataBind()
    DataAdap = Nothing
    ObjCmd = Nothing
    mObjConnOracle.Close()
    mObjConnOracle.Dispose()
    mObjConnOracle = Nothing
    End Sub
    Execute_Query "select * from map.t_mapa_def where mapa_def_cod = :p1 order by mapa_def_cod"
    ===== END VB.NET CODE =====

    Hi,
    BindByPosition is the default behavior as per the docs, and you can change that by setting cmd.BindByName=true which adds a little bit of extra overhead.
    That wont fix the error seen when binding a random number of parameters to the statement though. You need to bind the correct number and types of parameters.
    Greg

  • How much UNDO does a query need?

    It seems that due to a gigantic delete, I am running out of UNDO. How can I see exactly how much undo a query needs?
    Searching on the web, I found this:
    select sq.sql_text sql_text, t.USED_UREC Records, t.USED_UBLK Blocks, (t.USED_UBLK*8192/1024) KBytes from v$transaction t,
    v$session s,
    v$sql sq
    where t.addr = s.taddr
    and s.sql_id = sq.sql_id
    and s.username = 'blah'
    , which is fine, but it seems to be returning results for only running queries. In other words, when the delete query I am investigating is executed, the above select returns no rows. Is there a way to modify it to return also queries that have been executed?
    Any help is welcome.
    Message was edited by:
    user622271

    Hi,
    It seems that you need to make an outer join between v$sql and v$session views [s.sql_id = sq.sql_id(+)] ... For more information is if this [url http://forums.oracle.com/forums/thread.jspa?messageID=1756927&#1756927]thread can help you.
    Cheers
    Legatti

  • SQL query needed to identify cancelled invoice where distribution lines

    SQL query needed to identify cancelled invoice where distribution lines Debit is not equal Credit line item in particular
    Is there a way from back end FROM ap_invoice_distributions_all where we can find for the cancelled invoice where distribution lines Debit is not equal Credit line item
    Regards,
    Prakash Ranjan

    Hello Prakash
    Can you please see if this query helps you?
    SELECT i.invoice_id, i.invoice_amount, nvl(sum(d.amount),0)
    FROM ap_invoice_distributions_all d, ap_invoices_all i
    WHERE i.org_id = <you org_id>
    AND i.invoice_id = d.invoice_id
    AND d.line_type_lookup_code not in ('PREPAY')
    AND i.cancelled_date IS NOT NULL
    GROUP BY i.invoice_id, i.invoice_amount
    HAVING (i.invoice_amount <> nvl(sum(d.amount),0))
    ORDER BY i.invoice_id asc
    Octavio

  • How to find which query need to tuned

    Hi ,
    How can i find , which query need to tuned . Is there any mechanism behind it?

    The mechanisms behind it are depending on your database version.
    For example:
    Oracle 9i has STATSPACK that helps you to identify possible problem queries.
    Oracle 10g has AWR - Automatic Workload Repository
    Oracle 11g has SPA - Database Replay SQL Performance Analyzer
    but there are many more tools/mechanisms...trace/tkprof for example.
    Go to http://tahiti.oracle.com and do a search on 'performance tuning guide', and pick the one that matches your (sofar unknown) database version, read a bit every now and then and see what tools are at your disposal and fit your requirement and situation.
    Besides the links that Blu already posted, searches on http://asktom.oracle.com also give lots of pointers and explanations regarding the (neverending) tuning process (at least: helped me tremendously in understanding the tuning process, the do's and dont's).
    Make sure you don't get CTD (Compulsive Tuning Disorder) from all this... ;)

  • Query Jump with Navigation ( Sub query need to show same Navigation )

    Hi All.
       We have 4 BEx queries in our Dashboard Web Template and each table web items shows 10 rows and remaining with Scorll.
       For Printing ,we have created a query jump for each BEx Query ( same copy query) that shows all the rows detail.
       When i tried to jump from Orginial Dashboard ( From Specific table/Bex Query) with drill down <b>( Plant by Material )</b> , the jump query is not showing the same drill down but it showing the default rows <b>( Plant as per query rows</b>).
       SAP has suggested us its possible to do Query Jump with Navgiation that shows the same drill down path (navigation) in Sub Query as well.
       Am unable to find how to configure that , did search in OSS / Other Forumns But there were no postings on this.
       For me there is no Settings in RSBBS (or) SPRO and tried the Web Address Jump as well to pass the Drill Down Status (or) Navigation. May be iam not looking at right place. We are at 3.1x
       We found some limitations with SAP recommended web printing ( we dont need to discuss about that as per our requirement ), and our users like the Query Jump printing as which we working on now.
       Please inform if this can be possible, if so how.
    Thanks
    Martin Mouli

    Thanks for reply Bhanu.
    Its not like just Plant by Material.
    I would like to do my slicing & dicing on Navigational block with any combinations ( Customer by Plant by Material )
    When i do query jump from My Original Web Table , my jump query need to show the same drill down ( Customer by Plant by Material)but its showing only Material. ( Which is a default row in sub query)
    To show the same navigation in jump query as well, right now am doing drill down again in jump query as well. Its time waste to repeat the same drill down steps in sub query.
    By default my Jump Query has Material as row and We will show Plant & Customer on Demand (free characteristics)
    Please inform if more information required.
    Regards
    Martin Mouli

  • Monitoring via WMI - query needs a long time to get a result

    Hi experts!
    I am using Icinga (Nagios Fork) and a plugin called check_wmi_plus.pl (Perl Skript) which uses the wmic linux implementation.
    I have now multiple servers which needs very long to answer. I am using exactly the same command on the hosts. I give you an example here:
    Server-A:  WMI query needs ~70 Seconds, Ping Time is ~0.5-2.0 ms
    Server-B:  WMI query needs ~9 Seconds, Ping Time is ~90-120 ms
    I ran exactly the same command, from the same host, with the same user credentials and they are on the same domain.
    This behavior is not by the operting system because I have 2008r2 and 2003 servers which do both, need short and long time. They are all in different locations so there seems not to be a network issue. Hosts that are having the problems are 2008 hyper-v
    hosts but also 2003 file servers.. so I dont see any match here.
    I dont know how to go ahead, where to start the next troubleshooting steps?
    Is there any WMI log on the server I can monitor?
    Any help or ideas would be great! Thanks in advance!
    cheers, Duffkess

    this issue
    might related to the network issues, please check the Receive Side Scaling and
    the TCP Chimney registry settings. If TCP Chimney was enabled along with the
    RSS setting, WMI would fail.  <o:p></o:p>
    Meanwhile
    please test if the local basic WMI query also slow by
    Administrator account.<o:p></o:p>
    a. Run wbemtest, connect the namespace
    root\cimv2<o:p></o:p>
    b. Click Query… and enter query as: Select * from
    Win32_ComputerSystem. <o:p></o:p>
    c. Note down how many seconds does the query take.<o:p></o:p>
    Please also test if the remote basic WMI query is slow by
    Administrator account.<o:p></o:p>
    a. Run wbemtest, connect the namespace
    \\machinename\root\cimv2<o:p></o:p>
    b. Click Query… and enter query as: Select * from
    Win32_ComputerSystem. <o:p></o:p>
    c. Note down how many seconds does the query take.<o:p></o:p>
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • BEx query needs to count unique characteristic values

    Is there any way to build a query using BEx query designer to count the number of unique values of a characteristic.  For instance, my cube has detailed transactions for claim information.  Each claim number can have multiple products.  My query need to show the number of claims that exist for each product.  I don't want the detail of the claim number, just how many claims exist.
    Product          Gross Paid Loss        Claim Count
    Total Auto                $ 43,865.01              ?
    Total Property  $ 4,068,321.57              ?
    Not assigned                19,426

    Hi,
    Creat calculated  keyfigure with data functions Count value and save with technical name.
    Right click on that go to propertes, select count with exception aggregation - Claim Number,
    also use after aggregation and decimal places '0'.
    Regards
    Malyadri

  • Getting Brain Error while saving the query--Need Immediate solution

    Hello Experte
    I designed query like this.
    G/L account structure is defined in Rows. Before explaining about columns Let me Explain u about my ORG structure.
    Company codes are defined in R/3 like this.
    Company Code
    1000 for Local Currency(HSL01)
    2000 to 7000,IEL for group Currency(KSL01).
    Iu2019m extracting the data as it is from R/3 to DSO and again by writing routine I splitter the data for months(EX: HSL01 is ApriL,Hsl02 May,u2026u2026u2026u2026u2026u2026.KSL01 April, KSL02 may,u2026u2026u2026. Upto to 16 periods) this is R/3 data. This data I differentiated based upon currency types. If currency type is 10 then Local Currency 30 Means Group Currency.
    Again Iu2019m receiving the data from Flat Files for subsidiaries(IEAI,IEG,IEEL,ISSCI,IHAL,TTM-US,TTM-INDIA,TTIT). This data I loaded first into DSO by writing Routine at field Level for G/L account to convert G/L Descriptions into Numbers.
    After that I loaded data from first DSO to Second DSO by writing to convert respective currencies into INR and again loaded to cube by Direct mapping.
    Again Iu2019m receiving the eliminations data from R/3 through Ztable. This also Iu2019m extracting from R/3  and loaded into dso and again into cube.
    Now I will Explain about my Report.
    In Columns I defined 3 selections for each month.  U can observe that in Document. Like that for each month Iu2019m getting three selections and for subsidiaries 2 selections for each month. If we observe total Iu2019m getting 13 selections for India and 9 selections for each subsidiary. If subsidiaries increase I need to increase selections, automatically columns will increase. Now for Q4 2 new subsidiaries are  added I need to added. After adding and while saving the query then only Iu2019m getting brain error.
    Could any one sort out this.
    Thanks,
    Sony

    HI Ravi,
    Thanks for the reply.
    While saving the query in BEX i'm getting this error.
    Diagnosis
    Query ZQ3_MISGRPSUMMARYREPORT_010209 contains 8192 differing selection cells. However, only 8191 selection cells can be processed in a query.
    Procedure
    Please simplify query definition ZQ3_MISGRPSUMMARYREPORT_010209.
    This was the error i'm getting. How to simplify this....
    Any answers please.
    Thanks,
    Sony

  • A sql query needed

    Hi All,
    I have belwo two record values.
    select 1 as seq_no,'test1' as data_set from dual
    union
    select 1,'12test' from dual
    union
    select 2,'abcd' from dual
    union
    select 2,'ilm' from dual
    union
    select 2,'12test444' from dual
    here i need to extract the below o/p from from the above dataset
    1,12test
    1,test1
    2,12test444
    select 1 as seq_no,'test1' as data_set from dual
    union
    select 1,'12test' from dual
    union
    select 2,'abcd' from dual
    union
    select 2,'ilm' from dual
    here i need to extract the below o/p from from the above dataset
    1,12test
    1,test1
    2,abcd
    2,ilm
    The logic behind the above two types of o/p is
    if the search string 'test' is present in any data set (data set is defined by same seq_no values) then print the whole row containing the search string. As in the first record value data set with seq_val 1 and 2 both have test string 'test' , o/p is all the rows contating the search string 'test'
    If the search string 'test' is not present in any data set (data set is defined by same seq_no values) then print all other rows not containing the search string. As in the second record value data set with seq_val 2 both doesn't have test string 'test' , o/p is all the rows not contating the search string 'test' in data test with seq_val 1as well as all the rows contating the search string 'test' in data set with seq_val 2
    Hope i could explain my o/p logic and i need to perform this in a sql query.
    Waiting for your responses.
    Thanks in advance.

    Hi,
    Here's one way:
    WITH     got_rnk          AS
         SELECT     seq_no, data_set
         ,     DENSE_RANK () OVER ( PARTITION BY  seq_no
                                   ORDER BY          CASE
                                       WHEN  INSTR (data_set, 'test') > 0
                                       THEN  1
                                       ELSE  2
                                     END
                           )     AS rnk
         FROM    table_x
    SELECT     seq_no, data_set
    FROM     got_rnk
    WHERE     rnk     = 1
    ;The CASE expression returns 1 if data_set contains 'test', and it returns 2 if it does not. Let's call this number x.
    You're not really interested in x itself. Rather, you want all the rows that have the lowest value of x among rows with the same seq_no. That is, if any row with a given_seq_num has x=1, then you want all rows with that seq_no and x=1, but it the lowest x for the a seq_no is 2, then you want the rows with x=2 instead.
    DENSE_RANK returns the the number 1 if the given riow is the lowest (or tied for the lowest) in its partition, so if the are any rows with x=1 in the group, rnk=1 will correspond to x=1. But if all the rows with the same seq_no have x=2, then rnk=1 will correspond to x=2.

  • Tricky query needing clever SQL...

    A table called alt_websearch_log records the time it takes to complete each search performed on a website. I am therefore able to write something like this:
    select to_char(search_date,'DD/MON/YYYY'), count(*), avg(searchtime_secs), max(searchtime_secs)
    from alt_websearch_log
    group by to_char(search_date,'DD/MON/YYYY')
    order by to_char(search_date,'DD/MON/YYYY') desc
    ...and it works fine, giving me a daily average search time over a period of weeks or months for reporting to management. The trouble is that I have to periodically rebuild the indexes that make this search work, and during the time that the rebuild is taking place -not surprisingly- search performance slows down quite a bit.
    (Incidentally, I know not to rebuild indexes routinely, but these two are special, because they're Context indexes and the table on which they're built is itself completely reconstructed at weekends. It's a weird system, but we have to do it that way, for lots of reasons I ask you to take on trust, at least for now!)
    My rebuilding code has been modified to insert a line into the alt_websearch_log table, so that I can select from it and see this sort of thing:
    SESSION_ID SERVERNAME SEARCHTERMS SEARCHDATE
    99999999999 LOCALDBSRVR START REBUILD 15/7/2008 16:00
    And when the rebuild completes, I put a very similar line that says 'STOP REBUILD' at (say) 15/7/2008 18:00
    So what I would like to be able to do is to run the same sort of query as I started with, but with all the searches that take place between a start and stop rebuild marker being ignored for the purposes of computing the average and maximum.
    My problem is that I cannot conceive of a query that discards rows between a start and stop time that happens repeatedly (for example, I would have a START/STOP pair on 8th July, 1st July, 23 June and so on, but because manual rebuilds might sometimes happen, there's no definite pattern for when such pairs occur).
    In other words, if the sorted data ran;
    1/7/08 10:00 1.3secs
    1/7/08 10.05 1.4 secs
    1/7/08 10:10 start rebuild
    1/7/08 10:11 2.5 secs
    1/7/08 10:12 4.5 secs
    1/7/08 10:15 stop rebuild
    1/7/08 10:16 1.1 secs
    2/7/08 11:00 1.1secs
    2/7/08 11.03 1.1 secs
    2/7/08 11:05 start rebuild
    2/7/08 11:14 3.1 secs
    2/7/08 11:16 3.6 secs
    2/7/08 11:25 stop rebuild
    2/7/08 11:36 1.2 secs
    ...I would want 1.3, 1.4 and 1.1 to be averaged to a total of 1.267 for 1/7/08, and the two 2 second plus searches on that to be ignored for reporting purposes. And then I'd need the average for 2/7/08 to be reported as 1.13 seconds, with the two 3+ second response times ignored, because they were recorded between that day's start/stop rebuild markers.
    Whilst it is theoretically possible that a 'start' could begin at, say 5 to midnight and its corresponding 'stop' wouldn't be recorded until 5 past midnight, if it makes it any easier, you can assume that a start and a stop always share the same date.
    It is also possible in real life that we might do more than one rebuild per day, but if it makes it any easier, it's OK to assume only one start/stop marker will be recorded per day. (Actually, it would be nice if you didn't have to assume that, because this is a situation I know we would definitely face at some point in the future).
    I'd very much appreciate some insight into any SQL techniques that can be used to deal with this issue. I am guessing some of the modelling commands might be useful, but I don't know where to begin on that. I'm using 10.2.0.3 on Windows.
    Sorry for the long question. Grateful for any help.

    OK build a sample table,
    create table alt_websearch_log
    (search_date date,
    search_time_secs numeric(9,2),
    searchterms varchar2(50));
    insert into alt_websearch_log values (to_date('1/7/08 10:00','dd/mm/yy hh24:mi'),1.3,'bob,sally');
    insert into alt_websearch_log values (to_date('1/7/08 10:05','dd/mm/yy hh24:mi'),1.4,'dev');
    insert into alt_websearch_log values (to_date('1/7/08 10:10','dd/mm/yy hh24:mi'),null,'start rebuild');
    insert into alt_websearch_log values (to_date('1/7/08 10:11','dd/mm/yy hh24:mi'),2.5,'code');
    insert into alt_websearch_log values (to_date('1/7/08 10:12','dd/mm/yy hh24:mi'),4.5,'nugget');
    insert into alt_websearch_log values (to_date('1/7/08 10:15','dd/mm/yy hh24:mi'),null,'stop rebuild');
    insert into alt_websearch_log values (to_date('1/7/08 10:16','dd/mm/yy hh24:mi'),1.1,'random');
    insert into alt_websearch_log values (to_date('2/7/08 11:00','dd/mm/yy hh24:mi'),1.1,'search');
    insert into alt_websearch_log values (to_date('2/7/08 11:03','dd/mm/yy hh24:mi'),1.1,'term');
    insert into alt_websearch_log values (to_date('2/7/08 11:05','dd/mm/yy hh24:mi'),null,'start rebuild');
    insert into alt_websearch_log values (to_date('2/7/08 11:14','dd/mm/yy hh24:mi'),3.1,null);
    insert into alt_websearch_log values (to_date('2/7/08 11:16','dd/mm/yy hh24:mi'),3.1,null);
    insert into alt_websearch_log values (to_date('2/7/08 11:25','dd/mm/yy hh24:mi'),null,'stop rebuild');
    insert into alt_websearch_log values (to_date('2/7/08 11:36','dd/mm/yy hh24:mi'),3.1,null);
    insert into alt_websearch_log values (to_date('2/7/08 11:39','dd/mm/yy hh24:mi'),1.1,'tube');
    commit;then try this..
    col av_stime for 99.99
    col max_s_time for 99.99
    select trunc(search_date),avg(SEARCH_TIME_SECS) av_stime,max(search_time_secs) max_s_time from
    (select search_date,search_time_secs,
    nvl((LAST_VALUE(decode(searchterms,'stop rebuild','stop rebuild','start rebuild','start rebuild',null) IGNORE NULLS) over
    (ORDER BY search_date ROWS BETWEEN UNBOUNDED PRECEDING AND current row)),'stop rebuild') AS term
    from alt_websearch_log) a
    where term = 'stop rebuild'
    group by trunc(search_date)
    order by trunc(search_date) desc;
    TRUNC(SEA AV_STIME MAX_S_TIME
    02-JUL-08     1.60       3.10
    01-JUL-08     1.27       1.40this work accross days and with multiple rebuilds, randolphs comments apply if
    the logic is broken and a rebuild deosn't get logged correctly this will return odd
    results. It may be safer to add an additional column to log the rebuilds as you will
    have a problem is a user searches for one of the two key terms. Also I have
    assumed the search_time_secs will be null when you log the rebuilds.
    Chris

  • Query Needed for Partitioning table

    Hi,
    I have created a table called Test. There is a column named business_name.
    There are several businesses like ABC,BCD,ADE....
    There will be lakhs of rows corresponding to each business, i mean there will be lakhs of entires corresponding to ABC,BCD....
    So i like to partition the table according to business_name so that the search will be more faster.As we had partitioned according to the business_name, i hope we need to search only on the partition corresponding to the particular business.
    can any one provide the Query to partition the table ' TEST ' according to the column ' business_name ' .
    Also can anyone provide Query to modify the already existing table ' TEST ' to incorporate partition for the column ' business_name '.

    We can partiton a table by the following
    create table Generalledger (
         record_id     number,
         business_name     varchar2(3)
         sales_dt     date,
         amount     number(10)
    partition by list (business_name)
    partition ct values ('ABC'),
    partition ca values ('BCD'),
    partition def values (default)
    But if we dont know the values like 'ABC' , 'BCD'
    ....how can we do the partitionuse SQL to generate part (or all) of your DDL statement. The following will output one partition statement for each business_name:
    SELECT DISTINCT 'partition p_' || BUSINESS_NAME || ' values (''' ||
                     BUSINESS_NAME || '''),'
    FROM GENERALLEDGER;

  • Sample select query needed

    hi
    sample table can be considered as scott.emp table
      CREATE TABLE "EMP"
       (     "EMPNO" NUMBER(4,0),
         "ENAME" VARCHAR2(10 BYTE),
         "JOB" VARCHAR2(9 BYTE),
         "MGR" NUMBER(4,0),
         "HIREDATE" DATE,
         "SAL" NUMBER(7,2),
         "DEPTNO" NUMBER(2,0)
    -- INSERTING into EMP
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7369,'SMITH','CLERK',7902,to_date('17-DEC-80','DD-MON-RR'),800,20);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7499,'ALLEN','SALESMAN',7698,to_date('20-FEB-81','DD-MON-RR'),1600,30);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7521,'WARD','SALESMAN',7698,to_date('22-FEB-81','DD-MON-RR'),1250,30);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7566,'JONES','MANAGER',7839,to_date('02-APR-81','DD-MON-RR'),2975,20);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7654,'MARTIN','SALESMAN',7698,to_date('28-SEP-81','DD-MON-RR'),1250,30);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7698,'BLAKE','MANAGER',7839,to_date('01-MAY-81','DD-MON-RR'),2850,30);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7782,'CLARK','MANAGER',7839,to_date('09-JUN-81','DD-MON-RR'),2450,10);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7788,'SCOTT','ANALYST',7566,to_date('19-APR-87','DD-MON-RR'),3000,20);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7839,'KING','PRESIDENT',null,to_date('17-NOV-81','DD-MON-RR'),5000,10);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7844,'TURNER','SALESMAN',7698,to_date('08-SEP-81','DD-MON-RR'),1500,30);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7876,'ADAMS','CLERK',7788,to_date('23-MAY-87','DD-MON-RR'),1100,20);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7900,'JAMES','CLERK',7698,to_date('03-DEC-81','DD-MON-RR'),950,30);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7902,'FORD','ANALYST',7566,to_date('03-DEC-81','DD-MON-RR'),3000,20);
    Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO) values (7934,'MILLER','CLERK',7782,to_date('23-JAN-82','DD-MON-RR'),1300,10); In this we can see we do not have any data for the hiredate between '01-feb-81' and '20-feb-81' . But the select statement must retrun
    values in between those days too with ename,job AS NULL and empno, mgr,sal as 0,depno can be 0 or any number.
    i have tried something and i got the count for few columns . THe query goes something like this.
    this works on a given date range . Both queries given below
    select rt.business_date,
    ( select count(ename) from emp  where trunc(hiredate) = trunc(rt.business_date) )  ename ,
    ( select count(empno) from emp  where trunc(hiredate) = trunc(rt.business_date) )  empno ,
    ( select count(job) from emp  where trunc(hiredate) = trunc(rt.business_date) )  job,
    ( select count(mgr) from emp  where trunc(hiredate) = trunc(rt.business_date) )  mgr ,
    ( select count(deptno) from emp  where trunc(hiredate) = trunc(rt.business_date) )  deptno
    FROM (select ((TO_DATE(p_startdate,'mm/dd/yyyy')-1)+rnm) as business_date from (select rownum rnm from user_objects)) rt
                 WHERE TRUNC(rt.business_date) BETWEEN TO_DATE(p_startdate,'mm/dd/yyyy') AND  TO_DATE(p_enddate,'mm/dd/yyyy')
            SAMPLE OUTPUT FROM select statement has to be something like this :
    empno     ename      job     mgr     HIREDATE     SAL     DEPTNO     
    7369     SMITH     CLERK     7902     17-Dec-80     800     20     
    0     NULL     NULL     0     14-Feb-81     0     0     
    0     NULL     NULL     0     15-Feb-81     0     0     
    0     NULL     NULL     0     16-Feb-81     0     0     
    0     NULL     NULL     0     17-Feb-81     0     0     
    0     NULL     NULL     0     18-Feb-81     0     0     
    0     NULL     NULL     0     19-Feb-81     0     0     
    7499     ALLEN     SALESMAN     7698     20-Feb-81     1600     30     
    7521     WARD     SALESMAN     7698     22-Feb-81     1250     30     
    7566     JONES     MANAGER     7839     2-Apr-81     2975     20     
    7698     BLAKE     MANAGER     7839     1-May-81     2850     30     
    7782     CLARK     MANAGER     7839     9-Jun-81     2450     10     
    7844     TURNER     SALESMAN     7698     8-Sep-81     1500     30     
    7654     MARTIN     SALESMAN     7698     28-Sep-81     1250     30     
    7839     KING     PRESIDENT     (null)     17-Nov-81     5000     10     
    7900     JAMES     CLERK     7698     3-Dec-81     950     30     
    7902     FORD     ANALYST     7566     3-Dec-81     3000     20     
    7934     MILLER     CLERK     7782     23-Jan-82     1300     10     
    7788     SCOTT     ANALYST     7566     19-Apr-87     3000     20     
    7876     ADAMS     CLERK     7788     23-May-87     1100     20     Edited by: sri on Oct 19, 2011 8:36 AM
    Edited by: sri on Oct 19, 2011 8:56 AM

    Hi,
    You changed your first message.
    sri wrote:
    hi,
    i want the table data to be displayed as shown . in the quereis we are getting count of those records for that date. But i want something different . if we can see some dates there are no records but in the select statement we need to display the records in the given range of dates.
    the out put can be cosnidered something like this:
    THe select statment need to display hiredates data for 14 - 20 feb as shown below and this we do not have in our base table emp.
    empno     ename      job     mgr     HIREDATE     SAL     DEPTNO     
    7369     SMITH     CLERK     7902     17-Dec-80     800     20     
    0     NULL     NULL     0     14-Feb-81     0     0     
    0     NULL     NULL     0     15-Feb-81     0     0     
    0     NULL     NULL     0     16-Feb-81     0     0     
    0     NULL     NULL     0     17-Feb-81     0     0     
    0     NULL     NULL     0     18-Feb-81     0     0     
    0     NULL     NULL     0     19-Feb-81     0     0     
    7499     ALLEN     SALESMAN     7698     20-Feb-81     1600     30     
    7521     WARD     SALESMAN     7698     22-Feb-81     1250     30     
    7566     JONES     MANAGER     7839     2-Apr-81     2975     20     
    7698     BLAKE     MANAGER     7839     1-May-81     2850     30     
    7782     CLARK     MANAGER     7839     9-Jun-81     2450     10     
    7844     TURNER     SALESMAN     7698     8-Sep-81     1500     30     
    7654     MARTIN     SALESMAN     7698     28-Sep-81     1250     30     
    7839     KING     PRESIDENT     (null)     17-Nov-81     5000     10     
    7900     JAMES     CLERK     7698     3-Dec-81     950     30     
    7902     FORD     ANALYST     7566     3-Dec-81     3000     20     
    7934     MILLER     CLERK     7782     23-Jan-82     1300     10     
    7788     SCOTT     ANALYST     7566     19-Apr-87     3000     20     
    7876     ADAMS     CLERK     7788     23-May-87     1100     20
    Use a FULL OUTER JOIN instead of LEFT OUTER JOIN, like this:
    WITH     all_dates  AS
         SELECT     startdate + LEVEL - 1     AS dt
         FROM     (
                   SELECT     TO_DATE ('02/14/1981', 'MM/DD/YYYY')     AS startdate
                   ,     TO_DATE ('02/20/1981', 'MM/DD/YYYY')     AS enddate
                   FROM     dual
         CONNECT BY     LEVEL <= 1+ enddate - startdate
    SELECT       NVL (e.empno, 0)          AS empno
    ,       e.ename
    ,       NVL (a.dt, e.hiredate)     AS hiredate
    --  add other columns
    FROM                 all_dates     a
    FULL OUTER JOIN      emp          e  ON  a.dt = e.hiredate
    ORDER BY  NVL (a.dt, e.hiredate)
    ;

  • Trying to form complex query - need help

    I have a fairly complex query that I need to join the results of to show actual and goal by day. The actuals are an aggregation of records that get put in every day, while the targets are a single entry in range format indicating an active range for which the target applies. I'm working on a query that will put things together by month and I'm running into a snag. Can someone please point out where appropriate naming needs to go to get this to come together?
    This one works:
    (select DATE_INDEX, SUM(LDS) as TTLLDS, SUM(TONS) as TTLTONS from
        (select DATE_INDEX, VEH_LOC, SUM(LDS) as LDS, SUM(WT) as TONS from
           (select c.DATE_INDEX, c.VEH_LOC, COUNT(j.LOAD_JOB_ID) as LDS,
                 CASE WHEN SUM(w.SPOT_WEIGHT) = 0 THEN SUM(j.MAN_SPOT_WT)
                      ELSE SUM(w.SPOT_WEIGHT)
                  END as WT
              from TC c, TC_LOAD_JOBS j, LOAD_RATES r, SPOT_WEIGHTS w
             where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
               and c.DATE_INDEX = w.DATE_INDEX and j.LOAD_RATE_ID = w.LOAD_RATE_ID
               and c.VEH_LOC in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
               and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
             group by c.DATE_INDEX, c.VEH_LOC
            union
            select c.DATE_INDEX, c.VEH_LOC, COUNT(j.JOB_ID) as LDS,
                 DECODE(SUM(j.AVG_SPOT_WEIGHT),0,SUM(r.BID_TONS),SUM(j.AVG_SPOT_WEIGHT)) as WT
              from TC_3RDPARTY c, TC_3RDPARTY_JOBS j, LOAD_RATES r
             where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
               and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
               and j.FACTORY_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
             group by c.DATE_INDEX, c.VEH_LOC)
          group by DATE_INDEX, VEH_LOC)
      group by DATE_INDEX)Now I need to add in the following query:
    select (u.MACH_TPH_D+u.MACH_TPH_N)/2 as MTPH_TGT, (u.LABOR_TPH_D+u.LABOR_TPH_N)/2 as LTPH_TGT
         from UTIL_TARGET_LOADERS u
        where u.ORG_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)The join needs to be based on VEH_LOC and DAY in the form:
       ... WHERE u.ORG_ID = x.VEH_LOC
              AND x.DATE_INDEX between u.START_DATE and NVL(u.END_DATE,sysdate)I had one that worked just fine when only one entity was involved; the complication arises in that this is a division-level report so I have to individually resolve the subordinates and their goals before I can aggregate. This is one of two queries I need to tie together using a WITH clause so I can pivot the whole thing and present it in month-by-month fashion. When I try to tie it together like the query below, I get: invalid relational operator.
    select ttls.DATE_INDEX, SUM(ttls.LDS) as TTLLDS, SUM(ttls.TONS) as TTLTONS, u.TARGET_LTPH, u.TARGET_MTPH
      from UTIL_TARGET_LOADERS u,
        (select DATE_INDEX, VEH_LOC, SUM(LDS) as LDS, SUM(WT) as TONS from
           (select c.DATE_INDEX, c.VEH_LOC, COUNT(j.LOAD_JOB_ID) as LDS,
                 CASE WHEN SUM(w.SPOT_WEIGHT) = 0 THEN SUM(j.MAN_SPOT_WT)
                      ELSE SUM(w.SPOT_WEIGHT)
                  END as WT
              from TC c, TC_LOAD_JOBS j, LOAD_RATES r, SPOT_WEIGHTS w
             where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
               and c.DATE_INDEX = w.DATE_INDEX and j.LOAD_RATE_ID = w.LOAD_RATE_ID
               and c.VEH_LOC in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
               and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
             group by c.DATE_INDEX, c.VEH_LOC
            union
            select c.DATE_INDEX, c.VEH_LOC, COUNT(j.JOB_ID) as LDS,
                 DECODE(SUM(j.AVG_SPOT_WEIGHT),0,SUM(r.BID_TONS),SUM(j.AVG_SPOT_WEIGHT)) as WT
              from TC_3RDPARTY c, TC_3RDPARTY_JOBS j, LOAD_RATES r
             where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
               and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
               and j.FACTORY_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
             group by c.DATE_INDEX, c.VEH_LOC)
          group by DATE_INDEX, VEH_LOC) ttls
        where ttls.DATE_INDEX beween u.START_DATE and NVL(u.END_DATE,sysdate)
          and ttls.VEH_LOC = u.ORG_ID
      group by ttls.DATE_INDEXI know this is a nested mess, as it has to grab the production from two tables for a range of VEH_LOC values and sum and aggregate by day and VEH_LOC, then I have to try and match that to the targets based on VEH_LOC and day. My final query is to aggregate the whole mess of sums and averages by month.
    I'd appreciate it if someone can point me in the right direction.

    Figured it out.
    select ttl.DATE_INDEX, SUM(ttl.LDS) as TTLLDS, SUM(ttl.TONS) as TTLTONS,
         AVG((u.MACH_TPH_D+u.MACH_TPH_N)/2) as MTPH_TGT,
         AVG((u.LABOR_TPH_D+u.LABOR_TPH_N)/2) as LTPH_TGT
      from
        (select DATE_INDEX, VEH_LOC, SUM(LDS) as LDS, SUM(WT) as TONS from
           (select c.DATE_INDEX, c.VEH_LOC, COUNT(j.LOAD_JOB_ID) as LDS,
                 CASE WHEN SUM(w.SPOT_WEIGHT) = 0 THEN SUM(j.MAN_SPOT_WT)
                      ELSE SUM(w.SPOT_WEIGHT)
                  END as WT
              from TC c, TC_LOAD_JOBS j, LOAD_RATES r, SPOT_WEIGHTS w
             where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
               and c.DATE_INDEX = w.DATE_INDEX and j.LOAD_RATE_ID = w.LOAD_RATE_ID
               and c.VEH_LOC in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
               and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
             group by c.DATE_INDEX, c.VEH_LOC
            union
            select c.DATE_INDEX, c.VEH_LOC, COUNT(j.JOB_ID) as LDS,
                 DECODE(SUM(j.AVG_SPOT_WEIGHT),0,SUM(r.BID_TONS),SUM(j.AVG_SPOT_WEIGHT)) as WT
              from TC_3RDPARTY c, TC_3RDPARTY_JOBS j, LOAD_RATES r
             where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
               and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
               and j.FACTORY_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
             group by c.DATE_INDEX, c.VEH_LOC)
          group by DATE_INDEX, VEH_LOC) ttl, UTIL_TARGET_LOADERS u
      where u.ORG_ID = ttl.VEH_LOC
        and ttl.DATE_INDEX between u.START_DATE and NVL(U.END_DATE,sysdate)
      group by ttl.DATE_INDEX, (u.LABOR_TPH_D+u.LABOR_TPH_N)/2

  • JPA: Complex query needed to load object / special processing on store

    I have what I think is a tricky situation with an ORM scenario, and I am wondering what I need to do to get JPA to work with this situation:
    I have a table that looks like:
    key_with_rev_id INTEGER (sequence based, unique pk)
    key_id INTEGER (sequence based)
    rev_id INTEGER (sequence based, with key_id forms unique index)
    del_flag VC(1)
    + various data fields
    The object would contain these attributes (preferably):
    key_id (as the "unique" id)
    max_rev_id (transient, defaults to null)
    + various data attributes
    When I load it -- for max_rev_id = null, it should basically do this:
    select <data fields> from revved_table
    where key_id = <object.key_id>
    and rev_id = (select max(rev_id) from revved_table where key_id = <object.key_id>)
    and del_flag is null or del_flag = 'N'
    The query is a little more complex when max_rev_id is not null, but same idea.
    Now then -- when I store the object, whether it is to insert or update, I want it to always insert rows, with the key_with_rev_id and rev_id values from the corresponding sequences. (On insert, it will also use another seq to populate key_id). When I delete, I also want to insert a new row, but set del_flag = 'Y'
    Is this too complex for JPA such that it would be a huge hassle, or is there an elegant way to set this up?
    My apologies for any unusual terminology in the above -- I am quite new to JPA.
    Thanks,
    ken clark

    Does anyone have any suggestions as to where to start looking?
    Thanks,
    ken

Maybe you are looking for