SQL Query - SCOM2012R2 Performance Counter

Need some assistance with a SQL query against my SCOM DW. I want this to do a select within a select. The inner select must collect the raw data for a performance counter, for the last 5 minutes. But SCOM will only give me counters that collected in the
last 5 minutes. What i want is the last value for every managed instance. - 1500 servers. 
The outer SELECT must then filter this by doing a count on how many servers it collected a value for that are above 80% - and then divide that number by the total managed servers to give me a percentage of servers above 80% memory used. Eg - it counts 10
servers are above 80%, but theres 100 servers - then gives me a final figure of 90%. 
select (count(abc.DaValue)) from (
  select
    vManagedEntity.Path
    ,vPerformanceRule.ObjectName
    ,vPerformanceRule.CounterName
    ,AVG(vPerfRaw.SampleValue) AS DaValue
  from vPerfRaw
    join vPerformanceRuleInstance on vPerformanceRuleInstance.PerformanceRuleInstanceRowid = vPerfRaw.PerformanceRuleInstanceRowid
    join vPerformanceRule on vPerformanceRule.RuleRowId = vPerformanceRuleInstance.RuleRowId
    join vManagedEntity on vManagedEntity.ManagedEntityRowid = vPerfRaw.ManagedEntityRowId
  where vPerfRaw.Datetime > DATEADD(minute, -20, GETUTCDATE())
  and vPerformanceRule.ObjectName = 'Memory'
  and vPerformanceRule.CounterName = 'PercentMemoryUsed'
  GROUP BY Path, ObjectName, CounterName, Name
  Order by DaValue DESC) 
  as abc
where abc.DaValue >= 80
This statement gives me the result
Msg 1033, Level 15, State 1, Line 15
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.
Any ideas ?

Latest update - 
SELECT count(DISTINCT abc.server) as NoOfServers,
count(case when abc.DaValue >= 90 then abc.DaValue end) 'MemoryAbove90%'
FROM( select TOP 100 PERCENT 
vManagedEntity.Path as Server ,vPerformanceRule.ObjectName 
,vPerformanceRule.CounterName ,AVG(vPerfRaw.SampleValue) AS DaValue
from Perf.vPerfRaw join vPerformanceRuleInstance on vPerformanceRuleInstance.PerformanceRuleInstanceRowid = vPerfRaw.PerformanceRuleInstanceRowid
join vPerformanceRule on vPerformanceRule.RuleRowId = vPerformanceRuleInstance.RuleRowId
join vManagedEntity on vManagedEntity.ManagedEntityRowid = vPerfRaw.ManagedEntityRowId
where vPerfRaw.Datetime > DATEADD(minute, -10, GETUTCDATE())
and vPerformanceRule.ObjectName = 'Memory' and vPerformanceRule.CounterName = 'PercentMemoryUsed'
GROUP BY Path, ObjectName, CounterName, Name
Order by DaValue DESC)  as abc
This gives me Total Servers collected from, and Total Servers found to have AVG collections over 90% for Memory Util. 
My KPI states that I must only display the number of servers that are above 90%, for more than 10minutes.
The problem with this is that when i run it over a 10 minute period, I get collections for about 40% of my managed servers only.
I want to know if anyone has a better way of collecting the perf data over a 10 minute period ? 
What i was thinking of doing is  running this query with time interval on 11 minutes, populating a temp table with the data, running the query
again with time interval on 1 minute ago, and comparing the results. IF it finds a match, I know that the server has been over 90% memory util for 10 minutes - then i can count it ? Its probably not entirely accurate, but Im out of ideas. From here, i want
to export the Values for Total Servers and TotalServersAbove90% into Excel, and build a guage off it that will reflect a % of Servers within SLA -Memory Util. 
Im not entirely familiar with SCOM collection intervals, IF I run the query for the last 1 minute - It seems to skip alot of servers and only returns
data from about 50, is that because its not cycling on those at that moment ? In which case my idea above wont work.
UPDATE 2 - i think this will do it
Our OPS guy just told me that we sample every 10min. So immediately im thinking, perhaps i can run the query for the last 11 minutes - IF more than
1 sample is above 90%, the server is above 90% for more than 10min.
But, when i run this query 
select TOP 100 Percent Path, AVG(SampleValue) AS Value, DateTime  from Perf.vPerfRaw pvpr  inner join vManagedEntity vme on pvpr.ManagedEntityRowId
= vme.ManagedEntityRowId  inner join vPerformanceRuleInstance vpri on pvpr.PerformanceRuleInstanceRowId = vpri.PerformanceRuleInstanceRowId  inner join vPerformanceRule vpr on vpr.RuleRowId = vpri.RuleRowId WHERE ObjectName = 'Memory' AND CounterName
= 'PercentMemoryUSed' AND Datetime > DATEADD(minute, -1, GETUTCDATE()) AND SampleValue >= 90 GROUP BY Path, SampleValue, DateTime ORDER BY DateTime DESC
I get a few servers, but some have more than 1 entry in the last 1 minute.  Which means that i cant compare 2 samples.
Perhaps i could say if ALL samples collected per server in that 11 minute period are > 90, 
then add 1 to MemoryAbove90% 

Similar Messages

  • SQL Query Having performance issues

    I need help on rewriting this query, I am having performance issues with the way it is now. I create a temporary table and query against it. Any help will be appreciated. Thanks, Antonio
    Here it is:
    create global temporary table pr_php_elig_tmp
    on commit preserve rows as
    SELECT UNIQUE A.SAK_PROV, A.CDE_SERVICE_LOC, a.sak_short
    FROM T_PR_PHP_ELIG A,
    T_PR_TYPE C
    WHERE C.SAK_PROV = A.SAK_PROV
    AND C.CDE_SERVICE_LOC = A.CDE_SERVICE_LOC
    AND C.CDE_PROV_TYPE not in ('01', '03', '08', '24', '27', '31')
    AND A.SAK_PROV_PGM not in (11, 13)
    AND A.DTE_END >= :il_current_date
    AND A.DTE_EFFECTIVE <= :il_prev_18_months
    AND NOT EXISTS (
    SELECT 'X'
    FROM T_PR_GRP_MBR T
    WHERE T.SAK_PROV = A.SAK_PROV
    AND T.CDE_SVC_LOC_MBR = A.CDE_SERVICE_LOC)
    AND NOT EXISTS (
    select a.sak_prov, a.cde_service_loc
    from t_pmp_svc_loc d
    where a.sak_prov = d.sak_prov
    and a.cde_service_loc = d.cde_service_loc
    and d.dte_end >= :il_current_date)
    ORDER BY A.SAK_PROV, A.CDE_SERVICE_LOC;
    select * from pr_php_elig_tmp
    minus
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_dntl_dtl temp01
                   WHERE temp01.sak_prov_perf = a.sak_prov
                   and temp01.cde_svc_loc_perf = a.cde_service_loc
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
                   HAVING MAX(temp01.DTE_FIRST_SVC) >= :il_prev_18_months
                   OR NVL(MAX(temp01.DTE_FIRST_SVC),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_dntl_hdr temp02
                   WHERE ( (temp02.prov_billing     = a.sak_prov
                   and temp02.cde_service_loc = a.cde_service_loc)
                   OR     (temp02.sak_prov_perf     = a.sak_prov
                   and temp02.cde_perf_svc_loc = a.cde_service_loc)
                   OR     (temp02.sak_prov_referring = a.sak_prov
                   and temp02.cde_svc_loc_ref_1 = a.cde_service_loc)
                   OR     (temp02.sak_prov_referring_2 = a.sak_prov
                   and temp02.cde_svc_loc_ref_2 = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
                   HAVING MAX(temp02.DTE_FINAL)     >= :il_prev_18_months
                   OR NVL(MAX(temp02.DTE_FINAL),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_phrm_hdr temp03
                   WHERE ( (temp03.prov_billing     = a.sak_prov and
                        temp03.cde_service_loc = a.cde_service_loc)
                   OR     (temp03.sak_prov_rendering = a.sak_prov and
                        temp03.cde_svc_loc_rend = a.cde_service_loc)
                   OR     (temp03.sak_presc_prov = a.sak_prov and
                        temp03.cde_svc_loc_presc = a.cde_service_loc)
                   OR     temp03.id_prov_prescrb = to_char(a.sak_prov) || a.cde_service_loc
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
                   HAVING     MAX(temp03.DTE_FINAL) >= :il_prev_18_months
                   OR     NVL(MAX(temp03.DTE_FINAL),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_phys_dtl temp04
              WHERE ( (temp04.sak_prov_perf     = a.sak_prov
                   and     temp04.cde_svc_loc_rend = a.cde_service_loc)
                   OR (temp04.sak_prov_referring = a.sak_prov
                   and     temp04.cde_svc_loc_ref_1 = a.cde_service_loc)
                   OR (temp04.sak_prov_referring_2 = a.sak_prov
                   and     temp04.cde_svc_loc_ref_2 = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING     MAX(temp04.DTE_LAST_SVC)     >= :il_prev_18_months
                   OR     NVL(MAX(temp04.DTE_LAST_SVC),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_phys_hdr temp05
              WHERE ( (temp05.prov_billing     = a.sak_prov
                   and     temp05.cde_service_loc     = a.cde_service_loc)
                   OR (temp05.sak_prov_perf     = a.sak_prov
                   and     temp05.cde_perf_svc_loc = a.cde_service_loc)
                   OR (temp05.sak_prov_referring = a.sak_prov
                   and     temp05.cde_svc_loc_ref_1 = a.cde_service_loc)
                   OR (temp05.sak_prov_referring_2 = a.sak_prov
                   and     temp05.cde_svc_loc_ref_2 = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING     MAX(temp05.DTE_FINAL) >= :il_prev_18_months
                   OR     NVL(MAX(temp05.DTE_FINAL),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_ub92_dtl temp06
              WHERE ( (temp06.sak_pr_other     = a.sak_prov
                   and     temp06.cde_scv_loc_other = a.cde_service_loc)
                   OR (temp06.sak_pr_other_2     = a.sak_prov
                   and     temp06.cde_svc_loc_other_2 = a.cde_service_loc)
                   OR (temp06.sak_pr_attend     = a.sak_prov
                   and     temp06.cde_svc_loc_attend = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING     MAX(temp06.DTE_LAST_SVC)     >= :il_prev_18_months
                   OR     NVL(MAX(temp06.DTE_LAST_SVC),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_deny_ub92_hdr temp07
              WHERE ( (temp07.prov_billing     = a.sak_prov
                   and     temp07.cde_service_loc     = a.cde_service_loc)
              OR (temp07.sak_pr_facility     = a.sak_prov
                   and     temp07.cde_svc_loc_fa     = a.cde_service_loc)
              OR (temp07.sak_pr_other     = a.sak_prov
                   and     temp07.cde_svc_loc_other = a.cde_service_loc)
              OR (temp07.sak_pr_other_2     = a.sak_prov
                   and     temp07.cde_svc_loc_other_2 = a.cde_service_loc)
              OR (temp07.sak_pr_attend     = a.sak_prov
                   and     temp07.cde_svc_loc_attend = a.cde_service_loc)
              OR     temp07.id_prov_attend     = to_char(a.sak_prov) || a.cde_service_loc
              OR     temp07.id_prov_other     = to_char(a.sak_prov) || a.cde_service_loc
              OR     temp07.id_prov_other_2     = to_char(a.sak_prov) || a.cde_service_loc
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp07.DTE_FINAL)     >= :il_prev_18_months
                   OR     NVL(MAX(temp07.DTE_FINAL),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_dntl_dtl temp08
              WHERE temp08.sak_prov_perf     = a.sak_prov
                   and temp08.cde_svc_loc_perf     = a.cde_service_loc
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp08.DTE_FIRST_SVC) >= :il_prev_18_months
                   OR     NVL(MAX(temp08.DTE_FIRST_SVC),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_dntl_hdr     temp09
              WHERE ( (temp09.prov_billing     = a.sak_prov
                   and     temp09.cde_service_loc     = a.cde_service_loc)
              OR (temp09.sak_prov_perf     = a.sak_prov
                   and     temp09.cde_perf_svc_loc = a.cde_service_loc)
              OR (temp09.sak_prov_referring = a.sak_prov
                   and     temp09.cde_svc_loc_ref_1 = a.cde_service_loc)
              OR (temp09.sak_prov_referring_2 = a.sak_prov
                   and     temp09.cde_svc_loc_ref_2 = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp09.DTE_FINAL)     >= :il_prev_18_months
                   OR     NVL(MAX(temp09.DTE_FINAL),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_pharm_hdr temp10
              WHERE ( (temp10.prov_billing     = a.sak_prov
                   and     temp10.cde_service_loc     = a.cde_service_loc)
              OR (temp10.sak_prov_rend     = a.sak_prov
                   and     temp10.cde_svc_loc_rend = a.cde_service_loc)
              OR (temp10.sak_presc_prov     = a.sak_prov
                   and     temp10.cde_svc_loc_presc = a.cde_service_loc)
              OR     temp10.id_prov_prescrb     = to_char(a.sak_prov) || a.cde_service_loc
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp10.DTE_FINAL)     >= :il_prev_18_months
                   OR     NVL(MAX(temp10.DTE_FINAL),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_phys_dtl temp11
              WHERE ( (temp11.sak_prov_perf     = a.sak_prov
                   and     temp11.cde_svc_loc_rend = a.cde_service_loc)
              OR (temp11.sak_prov_referring = a.sak_prov
                   and     temp11.cde_svc_loc_ref_1 = a.cde_service_loc)
              OR (temp11.sak_prov_referring_2 = a.sak_prov
                   and     temp11.cde_svc_loc_ref_2 = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp11.DTE_LAST_SVC)     >= :il_prev_18_months
                   OR     NVL(MAX(temp11.DTE_LAST_SVC),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_phys_hdr     temp12
              WHERE ( (temp12.prov_billing     = a.sak_prov
                   and     temp12.cde_service_loc     = a.cde_service_loc)
              OR (temp12.sak_prov_perf     = a.sak_prov
                   and     temp12.cde_perf_svc_loc = a.cde_service_loc)
              OR (temp12.sak_prov_referring = a.sak_prov
                   and     temp12.cde_svc_loc_ref_1 = a.cde_service_loc)
              OR (temp12.sak_prov_referring_2 = a.sak_prov
                   and     temp12.cde_svc_loc_ref_2 = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp12.DTE_FINAL)     >= :il_prev_18_months
                   OR     NVL(MAX(temp12.DTE_FINAL),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_ub92_dtl temp13
              WHERE ( (temp13.sak_pr_other     = a.sak_prov
                   and     temp13.cde_scv_loc_other = a.cde_service_loc)
                   OR (temp13.sak_pr_other_2     = a.sak_prov
                   and     temp13.cde_svc_loc_other_2 = a.cde_service_loc)
                   OR (temp13.sak_pr_attend     = a.sak_prov
                   and     temp13.cde_svc_loc_attend = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING     MAX(temp13.DTE_LAST_SVC)     >= :il_prev_18_months
                   OR     NVL(MAX(temp13.DTE_LAST_SVC),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim01.t_pd_ub92_hdr     temp14
              WHERE ( (temp14.prov_billing     = a.sak_prov
                   and     temp14.cde_service_loc     = a.cde_service_loc)
              OR (temp14.sak_pr_facility     = a.sak_prov
                   and     temp14.cde_svc_loc_fa     = a.cde_service_loc)
              OR (temp14.sak_pr_other_2     = a.sak_prov
                   and     temp14.cde_svc_loc_other_2 = a.cde_service_loc)
              OR (temp14.sak_pr_attend     = a.sak_prov
                   and     temp14.cde_svc_loc_attend = a.cde_service_loc)
              OR (temp14.sak_pr_other     = a.sak_prov
                   and     temp14.cde_svc_loc_other = a.cde_service_loc)
              OR     temp14.id_prov_attend     = to_char(a.sak_prov) || a.cde_service_loc
              OR     temp14.id_prov_other     = to_char(a.sak_prov) || a.cde_service_loc
              OR     temp14.id_prov_other_2     = to_char(a.sak_prov) || a.cde_service_loc
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp14.DTE_FINAL)     >= :il_prev_18_months
                   OR     NVL(MAX(temp14.DTE_FINAL),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_dental_dtl temp15
              WHERE temp15.sak_prov_perf     = a.sak_prov
                   and temp15.cde_svc_loc_perf     = a.cde_service_loc
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp15.DTE_FIRST_SVC) >= :il_prev_18_months
                   OR     NVL(MAX(temp15.DTE_FIRST_SVC),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_dental_hdr temp16
              WHERE ( (temp16.sak_prov_perf     = a.sak_prov
                   and     temp16.cde_perf_svc_loc = a.cde_service_loc)
              OR (temp16.sak_prov_referring = a.sak_prov
                   and     temp16.cde_svc_loc_ref_1 = a.cde_service_loc)
              OR (temp16.sak_prov_referring_2 = a.sak_prov
                   and     temp16.cde_svc_loc_ref_2 = a.cde_service_loc)
              OR (temp16.prov_billing     = a.sak_prov
                   and     temp16.cde_service_loc     = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING ((MAX(temp16.DTE_LAST_SVC) >= :il_prev_18_months
                   OR     NVL(MAX(temp16.DTE_LAST_SVC),0) = 0)
                   and (MAX(temp16.DTE_BILLED) >= :il_prev_18_months
                   OR     NVL(MAX(temp16.DTE_BILLED),0) = 0) )
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_phrm_hdr temp17
              WHERE ( (temp17.prov_billing     = a.sak_prov
                   and     temp17.cde_service_loc     = a.cde_service_loc)
              OR (temp17.sak_prov_rend     = a.sak_prov
                   and     temp17.cde_svc_loc_rend = a.cde_service_loc)
              OR (temp17.sak_presc_prov     = a.sak_prov
                   and     temp17.cde_svc_loc_presc = a.cde_service_loc)
              OR     temp17.id_prov_prescrb     = to_char(a.sak_prov) || a.cde_service_loc
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp17.DTE_BILLED)     >= :il_prev_18_months
                   OR     NVL(MAX(temp17.DTE_BILLED),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_phys_dtl temp18
              WHERE ( (temp18.sak_prov_perf     = a.sak_prov
                   and     temp18.cde_svc_loc_rend = a.cde_service_loc)
              OR (temp18.sak_prov_referring = a.sak_prov
                   and     temp18.cde_svc_loc_ref_1 = a.cde_service_loc)
              OR (temp18.sak_prov_referring_2 = a.sak_prov
                   and     temp18.cde_svc_loc_ref_2 = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp18.DTE_LAST_SVC)     >= :il_prev_18_months
                   OR     NVL(MAX(temp18.DTE_LAST_SVC),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_phys_hdr temp19
              WHERE ( (temp19.prov_billing     = a.sak_prov
                   and     temp19.cde_service_loc     = a.cde_service_loc)
              OR (temp19.sak_prov_perf     = a.sak_prov
                   and     temp19.cde_perf_svc_loc = a.cde_service_loc)
              OR (temp19.sak_prov_referring = a.sak_prov
                   and     temp19.cde_svc_loc_ref_1 = a.cde_service_loc)
              OR (temp19.sak_prov_referring_2 = a.sak_prov
                   and     temp19.cde_svc_loc_ref_2 = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING ((MAX(temp19.DTE_LAST_SVC) >= :il_prev_18_months
                   OR     NVL(MAX(temp19.DTE_LAST_SVC),0) = 0)
                   and (MAX(temp19.DTE_BILLED)     >= :il_prev_18_months
                   OR     NVL(MAX(temp19.DTE_BILLED),0) = 0) )
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_ub92_dtl temp20
              WHERE ( (temp20.sak_pr_other     = a.sak_prov
                   and     temp20.cde_scv_loc_other = a.cde_service_loc)
                   OR (temp20.sak_pr_other_2     = a.sak_prov
                   and     temp20.cde_svc_loc_other_2 = a.cde_service_loc)
                   OR (temp20.sak_pr_attend     = a.sak_prov
                   and     temp20.cde_svc_loc_attend = a.cde_service_loc)
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING     MAX(temp20.DTE_LAST_SVC)     >= :il_prev_18_months
                   OR     NVL(MAX(temp20.DTE_LAST_SVC),0) = 0
    union
    select a.sak_prov, a.cde_service_loc, a.sak_short from pr_php_elig_tmp a, aim00.t_susp_ub92_hdr temp22
              WHERE ( (temp22.prov_billing     = a.sak_prov
                   and     temp22.cde_service_loc     = a.cde_service_loc)
              OR (temp22.sak_pr_facility     = a.sak_prov
                   and     temp22.cde_svc_loc_fa     = a.cde_service_loc)
              OR (temp22.sak_pr_other_2     = a.sak_prov
                   and     temp22.cde_svc_loc_other_2 = a.cde_service_loc)
              OR (temp22.sak_pr_attend     = a.sak_prov
                   and     temp22.cde_svc_loc_attend = a.cde_service_loc)
              OR (temp22.sak_pr_other     = a.sak_prov
                   and     temp22.cde_svc_loc_other = a.cde_service_loc)
              OR     temp22.id_prov_attend     = to_char(a.sak_prov) || a.cde_service_loc
              OR     temp22.id_prov_other     = to_char(a.sak_prov) || a.cde_service_loc
              OR     temp22.id_prov_other_2     = to_char(a.sak_prov) || a.cde_service_loc
                   GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
              HAVING MAX(temp22.DTE_BILLED)     >= :il_prev_18_months
                   OR     NVL(MAX(temp22.DTE_BILLED),0) = 0
    );

    Perhaps an approach like this would work better. No promises, but it's worth a try.
    SELECT *
      FROM pr_php_elig_tmp a
    WHERE NOT EXISTS (
             SELECT   a.sak_prov,
                      a.cde_service_loc,
                      a.sak_short
                 FROM aim01.t_deny_dntl_dtl temp01
                WHERE temp01.sak_prov_perf = a.sak_prov
                  AND temp01.cde_svc_loc_perf = a.cde_service_loc
             GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
               HAVING MAX (temp01.dte_first_svc) >= :il_prev_18_months
                   OR NVL (MAX (temp01.dte_first_svc), 0) = 0)
       AND NOT EXISTS (
             SELECT   a.sak_prov,
                      a.cde_service_loc,
                      a.sak_short
                 FROM aim01.t_deny_dntl_hdr temp02
                WHERE (   (    temp02.prov_billing = a.sak_prov
                           AND temp02.cde_service_loc = a.cde_service_loc)
                       OR (    temp02.sak_prov_perf = a.sak_prov
                           AND temp02.cde_perf_svc_loc = a.cde_service_loc)
                       OR (    temp02.sak_prov_referring = a.sak_prov
                           AND temp02.cde_svc_loc_ref_1 = a.cde_service_loc)
                       OR (    temp02.sak_prov_referring_2 = a.sak_prov
                           AND temp02.cde_svc_loc_ref_2 = a.cde_service_loc))
             GROUP BY a.sak_prov, a.cde_service_loc, a.sak_short
               HAVING MAX (temp02.dte_final) >= :il_prev_18_months
                   OR NVL (MAX (temp02.dte_final), 0) = 0)

  • SQL query/report for "count of specific file type"?

    I figured this would be a good first post, as I have found every question I have had to date by browsing the forums, but I am stumped with this one. I recently expressed some concern to HR regarding the use of...lets call it "unauthorized content"
    on our network. Getting little to no response, I would like to produce a report containing a total count based on specific file type. For example, how many .mp3 files are stored on company equipment, how many torrent files (sadly, this is true), etc.
    Having very basic knowledge of SQL, I am puzzled where to start. I am currently using SCCM SP3 and SQL 2008 R2 with both basic reporting and SSRS enabled on the site.

    You'll first need to inventory those file types then here's some reports for you.
    Get the pstreports from my skydrive, import them and you can cange the file type to mp3 or whatever you need. I monitor mp3 files too.
    http://cid-6a8d30f2bc0666d0.office.live.com/browse.aspx/SCCM%20Custom%20Reports
    John Marcum | http://myitforum.com/cs2/blogs/jmarcum/|

  • Sql query to get distinct count

    Hi
    I use SQL Server Management Studio
    can I have a sql query to get count as shown below against  each month column and name column to get distinct count.
    for example if there is two rows with the same date period and same name then the count should be one in first row and zero in the next row of the same data.
    Table Name: Table1
    Column: Month, Name
    Month
    Name
    Count
    12/1/2012 0:00
    AK
    1
    12/1/2012 0:00
    AK
    0
    12/1/2012 0:00
    AB
    1
    1/1/2013 0:00
    AK
    1
    1/1/2013 0:00
    AK
    0
    1/1/2013 0:00
    AB
    1
    3/1/2013 0:00
    AA
    1
    3/1/2013 0:00
    AK
    1
    3/1/2013 0:00
    AK
    0
    6/1/2013 0:00
    AA
    1
    6/1/2013 0:00
    AK
    1
    6/1/2013 0:00
    AK
    0
    9/1/2013 0:00
    AA
    1
    9/1/2013 0:00
    AK
    1
    9/13/2013 0:00
    AK
    1
    10/1/2013 0:00
    AA
    1
    10/1/2013 0:00
    AK
    1
    10/1/2013 0:00
    AK
    0

    Hi,
    Thanks for the query but this query gives the total count like shown below
    if see the second row in the below table AK for 2012-12-1 gives total count as 2 but need the query to show the first row as 1 and there after 0
    query result
    Month name cnt
    2012-12-01 00:00:00.000 AB 1
    2012-12-01 00:00:00.000 AK 2
    2012-12-01 00:00:00.000 AK 2
    2013-01-01 00:00:00.000 AB 1
    2013-01-01 00:00:00.000 AK 2
    2013-01-01 00:00:00.000 AK 2
    2013-03-01 00:00:00.000 AA 1
    2013-03-01 00:00:00.000 AK 2
    2013-03-01 00:00:00.000 AK 2
    2013-06-01 00:00:00.000 AA 1
    2013-06-01 00:00:00.000 AK 2
    2013-06-01 00:00:00.000 AK 2
    2013-09-01 00:00:00.000 AA 1
    2013-09-01 00:00:00.000 AK 1
    2013-09-13 00:00:00.000 AK 1
    2013-10-01 00:00:00.000 AA 1
    2013-10-01 00:00:00.000 AK 2
    2013-10-01 00:00:00.000 AK 2

  • Calculations Using SQL Query

    Hi All,
    I am using Oracle Database Version 11.2.
    I have a formula (A-B)/[(A-B)/10]. The tables that are holding the rows for this calculations are given below:
    ROWS_TAB
    ====== ===================
    Row          Amount
    ====== ===================
    A            5000
    B            -5000
    FORMULA_TAB
    ======== =========== ======== =============
    | ROW#  | Operator            | ROW        |   CONSTANT   |
    ======== =========== ======== =============
    | 10        |     E                   |      A       |                         |
    | 20        |     -                    |     B        |                         |
    | 30        |     E                   |      A       |                         |
    | 40        |     -                    |     B        |                         |
    | 50        |     /                    |               |      10                |
    | 60        |    /                     |               |                          |
    ======== =========== ======== =============
    The operator E starts a new calculation. The above formula has two sub-expressions thereby the table has two rows with E. Minus denoted by -, Plus denoted by +, Multiply denoted by *, and Division denoted by /.
    I want to write single SQL query to perform this calculation. Is it achievable in SQL?
    The scripts used to generate the tables are as below:
    create table ROWS_TAB
    (row_name VARCHAR2(1),
    amount NUMBER);
    create table FORMULA_TAB
    (row# NUMBER,
    operator VARCHAR2(1),
    row_name VARCHAR2(1),
    constant NUMBER);
    INSERT INTO ROWS_TAB VALUES('A', 5000);
    INSERT INTO ROWS_TAB VALUES('B', -5000);
    INSERT INTO FORMULA_TAB VALUES(10, 'E','A',null);
    INSERT INTO FORMULA_TAB VALUES(20, '-','B',null);
    INSERT INTO FORMULA_TAB VALUES(30, 'E','A',null);
    INSERT INTO FORMULA_TAB VALUES(40, '-','B',null);
    INSERT INTO FORMULA_TAB VALUES(50, '/','',10);
    INSERT INTO FORMULA_TAB VALUES(60, '/','','');
    Can anyone help in writing SQL query....
    Thanks in advance
    Best Regards
    Bilal

    As Frank said, it would be much easier to simply input the formula. Then, assuming you have OLAP option:
    variable formula varchar2(30)
    exec :formula := '(A-B)/((A-B)/10)';
    with t as (
               select  *
                 from  rows_tab
                 model
                   dimension by(row_number() over(order by row_name) r)
                   measures(
                            row_name,
                            amount,
                            count(*) over() cnt,
                            cast(:formula as varchar2(4000)) formula
                   rules(
                         formula[any] order by r = replace(nvl(formula[cv() - 1],formula[cv()]),row_name[cv()],amount[cv()])
    select  :formula || ' = ' || dbms_aw.eval_number(formula) result
      from  t
      where r = cnt
    RESULT
    (A-B)/((A-B)/10) = 10
    SQL>
    And if you do not have OLAP, you could use xquery:
    with t as (
               select  *
                 from  rows_tab
                 model
                   dimension by(row_number() over(order by row_name) r)
                   measures(
                            row_name,
                            amount,
                            count(*) over() cnt,
                            cast(:formula as varchar2(4000)) formula
                   rules(
                         formula[any] order by r = replace(nvl(formula[cv() - 1],formula[cv()]),row_name[cv()],amount[cv()])
    select  :formula || ' = ' || xmlquery(replace(formula,'/',' div ') returning content) result
      from  t
      where r = cnt
    RESULT
    (A-B)/((A-B)/10) = 10
    SQL>
    SY.

  • How to know which sql query is taking time for concurrent program

       Hi sir,
    I am running concurrent program,that is taking time to execute ,i want to know which sql query causing performance
    Thanaks,
    Sreekanth

    Hi,
    My Learning: Diagnosing Oracle Applications Concurrent Programmes - 11i/R12
    How to run a Trace for a Concurrent Program? (Doc ID 415640.1)
    FAQ: Common Tracing Techniques in Oracle E-Business Applications 11i and R12 (Doc ID 296559.1)
    How To Get Level 12 Trace And FND Debug File For Concurrent Programs (Doc ID 726039.1)
    How To Trace a Concurrent Request And Generate TKPROF File (Doc ID 453527.1)
    Regards
    Yoonas

  • How to create graph based on sql query

    Hi all,
    I am using jdev 10.1.3.3
    My requirement is need to ctreate graph(pie chart) based on sql query ex: select count(empno) from emp group by deptno;
    and also i need to give link on graph. If i click 10 deptno part in pie chart only 10 deptno employee list need to display.
    Please help meeeeeee
    Thanks
    NR

    Hi,
    just non click able graph in ADF 10g using BI Graph: http://www.freewebalbum.com/blogs/faces/bjanko/blogs.jsp?blog=bjanko20070629162305
    regards,
    Branislav

  • SQL Query Performance

    Hi There,
    We have a sql query that runs between 2 databases on the same machine, the sql takes about 2 mins and returns about 6400 rows. When the process started running we used to see results in about 13 secs, now it's taking almost 2 mins for the same data set. We have updated the stats (table and index) but to no use. I've been trying to get the execution plan to see if there is anything abnormal going on but as the core of the sql is done remotely, we haven't been able to get much out of it.
    Here is the sql:
    SELECT  
    --/*+ DRIVING_SITE(var) ALL_ROWS */
             ventity_id, ar_action_performed, action_date,
             'ventity_ar' ar_tab
        FROM (SELECT var.ventity_id, var.ar_action_performed, var.action_date,
                     var.familyname_id, var.status, var.isprotected,
                     var.dateofbirth, var.gender, var.sindigits,
                     LAG (var.familyname_id) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                lag_familyname_id,
                     LAG (var.status) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                       lag_status,
                     LAG (var.isprotected) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                  lag_isprotected,
                     LAG (var.dateofbirth) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                  lag_dateofbirth,
                     LAG (var.gender) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                       lag_gender,
                     LAG (var.sindigits) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                    lag_sindigits
                FROM cpp_schema.ventity_ar@CdpP var,
                     -- reduce the set to ventity_id that had a change within the time frame,
                     -- and filter out RETRIEVEs as they do not signal change
                     (SELECT DISTINCT ventity_id
                                 FROM cpp_schema.ventity_ar@CdpP
                                WHERE action_date BETWEEN '01-MAR-10' AND '10-APR-10'
                                  AND ar_action_performed <> 'RTRV') m
               WHERE var.action_date <= '10-APR-10'
                 AND var.ventity_id = m.ventity_id
                 AND var.ar_action_performed <> 'RTRV') mm
       WHERE action_date BETWEEN '01-MAR-10' AND '10-APR-10'
         -- most of the columns from the data table allow nulls
         AND (   (NVL (familyname_id, 0) <> NVL (lag_familyname_id, 0))
              OR (NVL (status, 'x') <> NVL (lag_status, 'x'))
              OR (NVL (isprotected, 2) <> NVL (lag_isprotected, 2))
              OR (NVL (dateofbirth, TO_DATE ('15000101', 'yyyymmdd')) <>
                           NVL (lag_dateofbirth, TO_DATE ('15000101', 'yyyymmdd'))
              OR (NVL (gender, 'x') <> NVL (lag_gender, 'x'))
              OR (NVL (sindigits, 'x') <> NVL (lag_sindigits, 'x'))
    ORDER BY ventity_id, action_date DESC
    6401 rows selected.
    Elapsed: 00:01:47.03
    Execution Plan
    Plan hash value: 3953446945
    | Id  | Operation        | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Inst   |IN-OUT|
    |   0 | SELECT STATEMENT |      |    12M|  1575M|       |   661K  (1)| 02:12:22 |        |      |
    |   1 |  SORT ORDER BY   |      |    12M|  1575M|  2041M|   661K  (1)| 02:12:22 |        |      |
    |*  2 |   VIEW           |      |    12M|  1575M|       |   291K  (2)| 00:58:13 |        |      |
    |   3 |    REMOTE        |      |       |       |       |            |          | CCP01  | R->S |
       2 - filter("action_date">='01_MAR-10' AND "action_date"<='10-APR-10' AND
                  (NVL("FAMILYNAME_id",0)<>NVL("LAG_FAMILYNAME_id",0) OR
                  NVL("STATUS",'x')<>NVL("LAG_STATUS",'x') OR NVL("ISPROTECTED",2)<>NVL("LAG_ISPROTECTED",2
                  ) OR NVL("DATEOFBIRTH",TO_DATE(' 1500-01-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss'))<>NVL("LAG_DATEOFBIRTH",TO_DATE(' 1500-01-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss')) OR NVL("GENDER",'x')<>NVL("LAG_GENDER",'x') OR
                  NVL("SINDIGITS",'x')<>NVL("LAG_SINDIGITS",'x')))
    Remote SQL Information (identified by operation id):
       3 - EXPLAIN PLAN SET STATEMENT_ID='PLUS4294967295' INTO PLAN_TABLE@! FOR SELECT
           "A2"."ventity_id","A2"."AR_ACTION_PERFORMED","A2"."action_date","A2"."FAMILYNAME_id","A2"
           ."STATUS","A2"."ISPROTECTED","A2"."DATEOFBIRTH","A2"."GENDER","A2"."SINDIGITS",DECODE(COU
           NT(*) OVER ( PARTITION BY "A2"."ventity_id" ORDER BY "A2"."action_date" ROWS  BETWEEN 1
           PRECEDING  AND 1 PRECEDING ),1,FIRST_VALUE("A2"."FAMILYNAME_id") OVER ( PARTITION BY
           "A2"."ventity_id" ORDER BY "A2"."action_date" ROWS  BETWEEN 1 PRECEDING  AND 1 PRECEDING
           ),NULL),DECODE(COUNT(*) OVER ( PARTITION BY "A2"."ventity_id" ORDER BY
           "A2"."action_date" ROWS  BETWEEN 1 PRECEDING  AND 1 PRECEDING ),1,FIRST_VALUE("A2"."STATUS")
           OVER ( PARTITION BY "A2"."ventity_id" ORDER BY "A2"."action_date" ROWS  BETWEEN 1
           PRECEDING  AND 1 PRECEDING ),NULL),DECODE(COUNT(*) OVER ( PARTITION BY
           "A2"."ventity_id" ORDER BY "A2"."action_date" ROWS  BETWEEN 1 PRECEDING  AND 1 PRECEDING
           ),1,FIRST_VALUE("A2"."ISPROTECTED") OVER ( PARTITION BY "A2"."ventity_id" ORDER BY
           "A2"."action_date" ROWS  BETWEEN 1 PRECEDING  AND 1 PRECEDING ),NULL),DECODE(COUNT(*) OVER (
           PARTITION BY "A2"."ventity_id" ORDER BY "A2"."action_date" ROWS  BETWEEN 1 PRECEDING
           AND 1 PRECEDING ),1,FIRST_VALUE("A2"."DATEOFBIRTH") OVER ( PARTITION BY
           "A2"."ventity_id" ORDER BY "A2"."action_date" ROWS  BETWEEN 1 PRECEDING  AND 1 PRECEDING
           ),NULL),DECODE(COUNT(*) OVER ( PARTITION BY "A2"."ventity_id" ORDER BY
           "A2"."action_date" ROWS  BETWEEN 1 PRECEDING  AND 1 PRECEDING ),1,FIRST_VALUE("A2"."GENDER")
           OVER ( PARTITION BY "A2"."ventity_id" ORDER BY "A2"."action_date" ROWS  BETWEEN 1
           PRECEDING  AND 1 PRECEDING ),NULL),DECODE(COUNT(*) OVER ( PARTITION BY
           "A2"."ventity_id" ORDER BY "A2"."action_date" ROWS  BETWEEN 1 PRECEDING  AND 1 PRECEDING
           ),1,FIRST_VALUE("A2"."SINDIGITS") OVER ( PARTITION BY "A2"."ventity_id" ORDER BY
           "A2"."action_date" ROWS  BETWEEN 1 PRECEDING  AND 1 PRECEDING ),NULL) FROM
           "CPP_SCHEMA"."ventity_AR" "A2", (SELECT DISTINCT "A3"."ventity_id"
           "ventity_id" FROM "CPP_SCHEMA"."ventity_AR" "A3" WHERE
           "A3"."action_date">='01_MAR-10' AND "A3"."action_date"<='10-APR-10' AND
           "A3"."AR_ACTION_PERFORMED"<>'RETRIEVE' AND TO_DATE('01_MAR-10')<=TO_DATE('10-APR-10'))
           "A1" WHERE "A2"."action_date"<='10-APR-10' AND "A2"."ventity_id"="A1"."ventity_id"
           AND "A2"."AR_ACTION_PERFORMED"<>'RETRIEVE' (accessing 'EBCP01.EBC.GOV.BC.CA' )Your advise and/or help is highly appreciated.
    THanks
    Edited by: rsar001 on Apr 20, 2010 6:57 AM

    Maybe I'm missing something but this subquery seems inefficient:
    SELECT var.ventity_id, var.ar_action_performed, var.action_date,
                     var.familyname_id, var.status, var.isprotected,
                     var.dateofbirth, var.gender, var.sindigits,
                     LAG (var.familyname_id) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                lag_familyname_id,
                     LAG (var.status) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                       lag_status,
                     LAG (var.isprotected) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                  lag_isprotected,
                     LAG (var.dateofbirth) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                  lag_dateofbirth,
                     LAG (var.gender) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                       lag_gender,
                     LAG (var.sindigits) OVER (PARTITION BY var.ventity_id ORDER BY action_date)
                                                                    lag_sindigits
                FROM cpp_schema.ventity_ar@CdpP var,
                     -- reduce the set to ventity_id that had a change within the time frame,
                     -- and filter out RETRIEVEs as they do not signal change
                     (SELECT DISTINCT ventity_id
                                 FROM cpp_schema.ventity_ar@CdpP
                                WHERE action_date BETWEEN '01-MAR-10' AND '10-APR-10'
                                  AND ar_action_performed <> 'RTRV') m
               WHERE var.action_date <= '10-APR-10'
                 AND var.ventity_id = m.ventity_id
                 AND var.ar_action_performed != 'RTRV'I don't think accessing the VENTITY_AR table twice is helping you here. The comments looks like you want to restrict the set of VENTITY_IDs but if you look at the plan it is not happening. The plan is reading them from the index and joining against the full VENTITY_AR table anyways. I recommend you consolidate it into something like this:
    SELECT  var.ventity_id
    ,       var.ar_action_performed
    ,       var.action_date
    ,       var.familyname_id
    ,       var.status
    ,       var.isprotected
    ,       var.dateofbirth
    ,       var.gender
    ,       var.sindigits
    ,       LAG (var.familyname_id) OVER (PARTITION BY var.ventity_id ORDER BY action_date)         AS lag_familyname_id
    ,       LAG (var.status) OVER (PARTITION BY var.ventity_id ORDER BY action_date)                AS lag_status
    ,       LAG (var.isprotected) OVER (PARTITION BY var.ventity_id ORDER BY action_date)           AS lag_isprotected
    ,       LAG (var.dateofbirth) OVER (PARTITION BY var.ventity_id ORDER BY action_date)           AS lag_dateofbirth
    ,       LAG (var.gender) OVER (PARTITION BY var.ventity_id ORDER BY action_date)                AS lag_gender
    ,       LAG (var.sindigits) OVER (PARTITION BY var.ventity_id ORDER BY action_date)             AS lag_sindigits
    FROM    cpp_schema.ventity_ar@CdpP var
    WHERE   var.action_date BETWEEN TO_DATE('01-MAR-10','DD-MON-YY') AND TO_DATE('10-APR-10','DD-MON-YY')
    AND     var.ar_action_performed != 'RTRV'It may then be useful to put an index on (ACTION_DATE,AR_ACTION_PERFORMED) if one doesn't already exist.
    *::EDIT::*
    I noticed the large amount of NVL calls in your outer query. These NVLs could possibly be eliminated if you use the optional second and third arguments of the LAG analytical function. I'm not sure if this would improve performance but it may make the query more readable and maintainable.
    HTH!
    Edited by: Centinul on Apr 20, 2010 10:50 AM

  • Need help in improving the performance for the sql query

    Thanks in advance for helping me.
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. The data count which is updated in the target table is 2 million records and the target table has 15 million records.
    Any suggestions or solutions for improving performance are appreciated
    SQL query:
    update targettable tt
    set mnop = 'G',
    where ( x,y,z ) in
    select a.x, a.y,a.z
    from table1 a
    where (a.x, a.y,a.z) not in (
    select b.x,b.y,b.z
    from table2 b
    where 'O' = b.defg
    and mnop = 'P'
    and hijkl = 'UVW';

    987981 wrote:
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. And that meant what? Surely if you spend all that time and effort to try various approaches, it should mean something? Failures are as important teachers as successes. You need to learn from failures too. :-)
    The data count which is updated in the target table is 2 million records and the target table has 15 million records.Tables have rows btw, not records. Database people tend to get upset when rows are called records, as records exist in files and a database is not a mere collection of records and files.
    The failure to find a single faster method with the approaches you tried, points to that you do not know what the actual performance problem is. And without knowing the problem, you still went ahead, guns blazing.
    The very first step in dealing with any software engineering problem, is to identify the problem. Seeing the symptoms (slow performance) is still a long way from problem identification.
    Part of identifying the performance problem, is understanding the workload. Just what does the code task the database to do?
    From your comments, it needs to find 2 million rows from 15 million rows. Change these rows. And then write 2 million rows back to disk.
    That is not a small workload. Simple example. Let's say that the 2 million row find is 1ms/row and the 2 million row write is also 1ms/row. This means a 66 minute workload. Due to the number of rows, an increase in time/row either way, will potentially have 2 million fold impact.
    So where is the performance problem? Time spend finding the 2 million rows (where other tables need to be read, indexes used, etc)? Time spend writing the 2 million rows (where triggers and indexes need to be fired and maintained)? Both?

  • SQL query performance issues.

    Hi All,
    I worked on the query a month ago and the fix worked for me in test intance but failed in production. Following is the URL for the previous thread.
    SQL query performance issues.
    Following is the tkprof file.
    CURSOR_ID:76  LENGTH:2383  ADDRESS:f6b40ab0  HASH_VALUE:2459471753  OPTIMIZER_GOAL:ALL_ROWS  USER_ID:443 (APPS)
    insert into cos_temp(
    TRX_DATE, DEPT, PRODUCT_LINE, PART_NUMBER,
    CUSTOMER_NUMBER, QUANTITY_SOLD, ORDER_NUMBER,
    INVOICE_NUMBER, EXT_SALES, EXT_COS,
    GROSS_PROFIT, ACCT_DATE,
    SHIPMENT_TYPE,
    FROM_ORGANIZATION_ID,
    FROM_ORGANIZATION_CODE)
    select a.trx_date,
    g.segment5 dept,
    g.segment4 prd,
    m.segment1 part,
    d.customer_number customer,
    b.quantity_invoiced units,
    --       substr(a.sales_order,1,6) order#,
    substr(ltrim(b.interface_line_attribute1),1,10) order#,
    a.trx_number invoice,
    (b.quantity_invoiced * b.unit_selling_price) sales,
    (b.quantity_invoiced * nvl(price.operand,0)) cos,
    (b.quantity_invoiced * b.unit_selling_price) -
    (b.quantity_invoiced * nvl(price.operand,0)) profit,
    to_char(to_date('2010/02/28 00:00:00','yyyy/mm/dd HH24:MI:SS'),'DD-MON-RR') acct_date,
    'DRP',
    l.ship_from_org_id,
    p.organization_code
    from   ra_customers d,
    gl_code_combinations g,
    mtl_system_items m,
    ra_cust_trx_line_gl_dist c,
    ra_customer_trx_lines b,
    ra_customer_trx_all a,
    apps.oe_order_lines l,
    apps.HR_ORGANIZATION_INFORMATION i,
    apps.MTL_INTERCOMPANY_PARAMETERS inter,
    apps.HZ_CUST_SITE_USES_ALL site,
    apps.qp_list_lines_v price,
    apps.mtl_parameters p
    where a.trx_date between to_date('2010/02/01 00:00:00','yyyy/mm/dd HH24:MI:SS')
    and to_date('2010/02/28 00:00:00','yyyy/mm/dd HH24:MI:SS')+0.9999
    and   a.batch_source_id = 1001     -- Sales order shipped other OU
    and   a.complete_flag = 'Y'
    and   a.customer_trx_id = b.customer_trx_id
    and   b.customer_trx_line_id = c.customer_trx_line_id
    and   a.sold_to_customer_id = d.customer_id
    and   b.inventory_item_id = m.inventory_item_id
    and   m.organization_id
         = decode(substr(g.segment4,1,2),'01',5004,'03',5004,
         '02',5003,'00',5001,5002)
    and   nvl(m.item_type,'0') <> '111'
    and   c.code_combination_id = g.code_combination_id+0
    and   l.line_id = b.interface_line_attribute6
    and   i.organization_id = l.ship_from_org_id
    and   p.organization_id = l.ship_from_org_id
    and   i.org_information3 <> '5108'
    and   inter.ship_organization_id = i.org_information3
    and   inter.sell_organization_id = '5108'
    and   inter.customer_site_id = site.site_use_id
    and   site.price_list_id = price.list_header_id
    and   product_attr_value = to_char(m.inventory_item_id)
    call        count       cpu   elapsed         disk        query      current         rows    misses
    Parse           1      0.47      0.56           11          197            0            0         1
    Execute         1   3733.40   3739.40        34893    519962154           11          188         0
    total           2   3733.87   3739.97        34904    519962351           11          188         1
    |         Rows Row Source Operation
    | ------------ ---------------------------------------------------
    |          188 HASH JOIN (cr=519962149 pr=34889 pw=0 time=2607.35)
    |          741 .TABLE ACCESS BY INDEX ROWID QP_PRICING_ATTRIBUTES (cr=519939426 pr=34889 pw=0 time=2457.32)
    |    254644500 ..NESTED LOOPS (cr=519939265 pr=34777 pw=0 time=3819.67)
    |    254643758 ...NESTED LOOPS (cr=8921833 pr=29939 pw=0 time=1274.41)
    |          741 ....NESTED LOOPS (cr=50042 pr=7230 pw=0 time=11.37)
    |          741 .....NESTED LOOPS (cr=48558 pr=7229 pw=0 time=11.35)
    |          741 ......NESTED LOOPS (cr=47815 pr=7223 pw=0 time=11.32)
    |         3237 .......NESTED LOOPS (cr=41339 pr=7223 pw=0 time=12.42)
    |         3237 ........NESTED LOOPS (cr=38100 pr=7223 pw=0 time=12.39)
    |         3237 .........NESTED LOOPS (cr=28296 pr=7139 pw=0 time=12.29)
    |         1027 ..........NESTED LOOPS (cr=17656 pr=4471 pw=0 time=3.81)
    |         1027 ...........NESTED LOOPS (cr=13537 pr=4404 pw=0 time=3.30)
    |          486 ............NESTED LOOPS (cr=10873 pr=4240 pw=0 time=0.04)
    |          486 .............NESTED LOOPS (cr=10385 pr=4240 pw=0 time=0.03)
    |          486 ..............TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_ALL (cr=9411 pr=4240 pw=0 time=0.02)
    |        75253 ...............INDEX RANGE SCAN RA_CUSTOMER_TRX_N5 (cr=403 pr=285 pw=0 time=0.38)
    |          486 ..............TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=974 pr=0 pw=0 time=0.01)
    |          486 ...............INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=488 pr=0 pw=0 time=0.01)
    |          486 .............INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=488 pr=0 pw=0 time=0.01)
    |         1027 ............TABLE ACCESS BY INDEX ROWID RA_CUSTOMER_TRX_LINES_ALL (cr=2664 pr=164 pw=0 time=1.95)
    |         2063 .............INDEX RANGE SCAN RA_CUSTOMER_TRX_LINES_N2 (cr=1474 pr=28 pw=0 time=0.22)
    |         1027 ...........TABLE ACCESS BY INDEX ROWID RA_CUST_TRX_LINE_GL_DIST_ALL (cr=4119 pr=67 pw=0 time=0.54)
    |         1027 ............INDEX RANGE SCAN RA_CUST_TRX_LINE_GL_DIST_N1 (cr=3092 pr=31 pw=0 time=0.20)
    |         3237 ..........TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=10640 pr=2668 pw=0 time=15.35)
    |         3237 ...........INDEX RANGE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=2062 pr=40 pw=0 time=0.33)
    |         3237 .........TABLE ACCESS BY INDEX ROWID OE_ORDER_LINES_ALL (cr=9804 pr=84 pw=0 time=0.77)
    |         3237 ..........INDEX UNIQUE SCAN OE_ORDER_LINES_U1 (cr=6476 pr=47 pw=0 time=0.43)
    |         3237 ........TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=3239 pr=0 pw=0 time=0.04)
    |         3237 .........INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=2 pr=0 pw=0 time=0.01)
    |          741 .......TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=6476 pr=0 pw=0 time=0.10)
    |         6474 ........INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=3239 pr=0 pw=0 time=0.03)Please help.
    Regards
    Ashish

    |    254644500 ..NESTED LOOPS (cr=519939265 pr=34777 pw=0 time=3819.67)
    |    254643758 ...NESTED LOOPS (cr=8921833 pr=29939 pw=0 time=1274.41)There is no way the optimizer should choose to process that many rows using nested loops.
    Either the statistics are not up to date, the data values are skewed or you have some optimizer parameter set to none default to force index access.
    Please post explain plan and optimizer* parameter settings.

  • How to make sql to use index/make to query to perform better

    Hi,
    I have 2 sql query which results the same.
    But both has difference in SQL trace.
    create table test_table
    (u_id number(10),
    u_no number(4),
    s_id number(10),
    s_no number(4),
    o_id number(10),
    o_no number(4),
    constraint pk_test primary key(u_id, u_no));
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030301, 1, 1001, 1, 2001, 1);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030302, 1, 1001, 1, 2001, 2);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030303, 1, 1001, 1, 2001, 3);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030304, 1, 1001, 1, 2001, 4);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030305, 1, 1002, 1, 1001, 2);
    insert into test_table(u_id, u_no, s_id, s_no, o_id, o_no)
    values (2007030306, 1, 1002, 1, 1002, 1);
    commit;
    CREATE INDEX idx_test_s_id ON test_table(s_id, s_no);
    set autotrace on
    select s_id, s_no, o_id, o_no
    from test_table
    where s_id <> o_id
    and s_no <> o_no
    union all
    select o_id, o_no, s_id, s_no
    from test_table
    where s_id <> o_id
    and s_no <> o_no;
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    3 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    Statistics
    223 recursive calls
    2 db block gets
    84 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    5 sorts (memory)
    0 sorts (disk)
    8 rows processed
    -- i didnt understand why the above query is not using the index idx_test_s_id.
    -- But still it is faster
    select s_id, s_no, o_id, o_no
    from test_table
    where (u_id, u_no) in
    (select u_id, u_no from test_table
    minus
    select u_id, u_no from test_table
    where s_id = o_id
    or s_no = o_no)
    union all
    select o_id, o_no, s_id, s_no
    from test_table
    where (u_id, u_no) in
    (select u_id, u_no from test_table
    minus
    select u_id, u_no from test_table
    where s_id = o_id
    or s_no = o_no);
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=16 Card=2 Bytes=156)
    1 0 UNION-ALL
    2 1 FILTER
    3 2 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=6 Bytes=468)
    4 2 MINUS
    5 4 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1 Bytes=26)
    6 4 TABLE ACCESS (BY INDEX ROWID) OF 'TEST_TABLE' (TABLE) (Cost=2 Card=1 Bytes=78)
    7 6 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1)
    8 1 FILTER
    9 8 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=6 Bytes=468)
    10 8 MINUS
    11 10 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1 Bytes=26)
    12 10 TABLE ACCESS (BY INDEX ROWID) OF 'TEST_TABLE' (TABLE) (Cost=2 Card=1 Bytes=78)
    13 12 INDEX (UNIQUE SCAN) OF 'PK_TEST' (INDEX (UNIQUE)) (Cost=1 Card=1)
    Statistics
    53 recursive calls
    8 db block gets
    187 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    4 sorts (memory)
    0 sorts (disk)
    8 rows processed
    -- The above query is using index PK_TEST. But still it has FULL SCAN to the
    -- table two times it has the more cost.
    1st query --> SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=8 Bytes=416)
    2nd query --> SELECT STATEMENT Optimizer=ALL_ROWS (Cost=16 Card=2 Bytes=156)
    My queries are:
    1) performance wise which query is better?
    2) how do i make the 1st query to use an index
    3) is there any other method to get the same result by using any index
    Appreciate your immediate help.
    Best regards
    Muthu

    Hi William
    Nice...it works.. I have added "o_id" and "o_no" are in part of the index
    and now the query uses the index
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    3 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    Statistics
    7 recursive calls
    0 db block gets
    21 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    507 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    But my questions are:
    1) In a where clause, if "<>" condition is used, then, whether the system will use the index. Because I have observed in several situations even though the column in where clause is indexed, since the where condition is "like" or "is null/is not null"
    then the index is not used. Same as like this, i assumed, if we use <> then indexes will not be used. Is it true?
    2) Now, after adding "o_id" and "o_no" columns to the index, the Execution plan is:
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    3 1 INDEX (FULL SCAN) OF 'IDX_TEST_S_ID' (INDEX) (Cost=1 Card=4 Bytes=208)
    Before it was :
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=8 Bytes=416)
    1 0 UNION-ALL
    2 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    3 1 TABLE ACCESS (FULL) OF 'TEST_TABLE' (TABLE) (Cost=3 Card=4 Bytes=208)
    Difference only in Cost (reduced), not in Card, Bytes.
    Can you explain, how can i decide which makes the performace better (Cost / Card / Bytes). Full Scan / Range Scan?
    On statistics also:
    Before:
    Statistics
    52 recursive calls
    0 db block gets
    43 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    507 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    After:
    Statistics
    7 recursive calls
    0 db block gets
    21 consistent gets
    0 physical reads
    0 redo size
    701 bytes sent via SQL*Net to client
    507 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    Difference in recursive calls & consistent gets.
    Which one shows the query with better performance?
    Please explain..
    Regards
    Muthu

  • Showing column value as counter in sql query - report

    I created a classic report with search bar based on an sql query. I would like to show the "notes" column in this query using some sort of counter and as a hyperlink to another section on the page (same idea as footnotes in a book). So if I have 10 rows and 5 have "notes". I should show 1,2,3,4,5 in the notes column for those rows and the number gets displayed as a link to another section listing the notes 1 through 5.
    I was thinking of creating a hidden page item as the counter with value of 0 and then in my query doing counter+1 but i'm not sure how to do this or if i can do that...
    If anyone can help or have any other ideas I would really appreciate it!!
    Thanks,
    Hindy

    Well, I'm doing this in VB and the subquery is dynamic. I'm passing an ADO recordset to a routine that sets up a listview to display the results. The number of columns selected can vary. My idea was to size the columns appropriately based on the size of the data. Within the display routine I could:
    sql = "SELECT "
    for i = 0 to oRS.Fields.Count - 1
    sql = sql & "MAX(LENGTH(" & i & ")), "
    next 'i
    sql = sql & "FROM (" & oRS.Source & ")"

  • How to measure the performance of sql query?

    Hi Experts,
    How to measure the performance, efficiency and cpu cost of a sql query?
    What are all the measures available for an sql query?
    How to identify i am writing optimal query?
    I am using Oracle 9i...
    It ll be useful for me to write efficient query....
    Thanks & Regards

    psram wrote:
    Hi Experts,
    How to measure the performance, efficiency and cpu cost of a sql query?
    What are all the measures available for an sql query?
    How to identify i am writing optimal query?
    I am using Oracle 9i... You might want to start with a feature of SQL*Plus: The AUTOTRACE (TRACEONLY) option which executes your statement, fetches all records (if there is something to fetch) and shows you some basic statistics information, which include the number of logical I/Os performed, number of sorts etc.
    This gives you an indication of the effectiveness of your statement, so that can check how many logical I/Os (and physical reads) had to be performed.
    Note however that there are more things to consider, as you've already mentioned: The CPU bit is not included in these statistics, and the work performed by SQL workareas (e.g. by hash joins) is also credited only very limited (number of sorts), but e.g. it doesn't cover any writes to temporary segments due to sort or hash operations spilling to disk etc.
    You can use the following approach to get a deeper understanding of the operations performed by each row source:
    alter session set statistics_level=all;
    alter session set timed_statistics = true;
    select /* findme */ ... <your query here>
    SELECT
             SUBSTR(LPAD(' ',DEPTH - 1)||OPERATION||' '||OBJECT_NAME,1,40) OPERATION,
             OBJECT_NAME,
             CARDINALITY,
             LAST_OUTPUT_ROWS,
             LAST_CR_BUFFER_GETS,
             LAST_DISK_READS,
             LAST_DISK_WRITES,
    FROM     V$SQL_PLAN_STATISTICS_ALL P,
             (SELECT *
              FROM   (SELECT   *
                      FROM     V$SQL
                      WHERE    SQL_TEXT LIKE '%findme%'
                               AND SQL_TEXT NOT LIKE '%V$SQL%'
                               AND PARSING_USER_ID = SYS_CONTEXT('USERENV','CURRENT_USERID')
                      ORDER BY LAST_LOAD_TIME DESC)
              WHERE  ROWNUM < 2) S
    WHERE    S.HASH_VALUE = P.HASH_VALUE
             AND S.CHILD_NUMBER = P.CHILD_NUMBER
    ORDER BY ID
    /Check the V$SQL_PLAN_STATISTICS_ALL view for more statistics available. In 10g there is a convenient function DBMS_XPLAN.DISPLAY_CURSOR which can show this information with a single call, but in 9i you need to do it yourself.
    Note that "statistics_level=all" adds a significant overhead to the processing, so use with care and only when required:
    http://jonathanlewis.wordpress.com/2007/11/25/gather_plan_statistics/
    http://jonathanlewis.wordpress.com/2007/04/26/heisenberg/
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • SQL Query Performance needed.

    Hi All,
       I am getting performance issue with my below sql query. When I fired it, It is taking 823.438 seconds, but when I ran query in, it is taking 8.578 seconds, and query after in   is taking 7.579 seconds.
    SELECT BAL.L_ID, BAL.L_TYPE, BAL.L_NAME, BAL.NATURAL_ACCOUNT,
     BAL.LOCATION, BAL.PRODUCT, BAL.INTERCOMPANY, BAL.FUTURE1, BAL.FUTURE2, BAL.CURRENCY, BAL.AMOUNT_PTD, BAL.AMOUNT_YTD, BAL.CREATION_DATE,
     BAL.CREATED_BY, BAL.LAST_UPDATE_DATE, BAL.LAST_UPDATED_BY, BAL.STATUS, BAL.ANET_STATUS, BAL.COG_STATUS, BAL.comb_id, BAL.MESSAGE,
     SEG.SEGMENT_DESCRIPTION  FROM ACC_SEGMENTS_V_TST SEG , ACC_BALANCE_STG BAL where BAL.NATURAL_ACCOUNT = SEG.SEGMENT_VALUE AND SEG.SEGMENT_COLUMN = 'SEGMENT99' AND BAL.ACCOUNTING_PERIOD = 'MAY-10' and BAL.comb_id
    in  
    (select comb_id from
     (select comb_id, rownum r from
      (select distinct(comb_id),LAST_UPDATE_DATE from ACC_BALANCE_STG where accounting_period='MAY-10' order by LAST_UPDATE_DATE )    
         where rownum <=100)  where r >0)
    Please help me in fine tuning above. I am using Oracle 10g database. There are total of 8000 records. Let me know if any other info required.
    Thanks in advance.

    In recent versions of Oracle an EXISTS predicate should produce the same execution plan as the corresponding IN clause.
    Follow the advice in the tuning threads as suggested by SomeoneElse.
    It looks to me like you could avoid the double pass on ACC_BALANCE_STG by using an analytical function like ROW_NUMBER() and then joining to ACC_SEGMENTS_V_TST SEG, maybe using subquery refactoring to make it look nicer.
    e.g. something like (untested)
    WITH subq_bal as
        ((SELECT *
          FROM (SELECT BAL.L_ID, BAL.L_TYPE, BAL.L_NAME, BAL.NATURAL_ACCOUNT,
                 BAL.LOCATION, BAL.PRODUCT, BAL.INTERCOMPANY, BAL.FUTURE1, BAL.FUTURE2,
                 BAL.CURRENCY, BAL.AMOUNT_PTD, BAL.AMOUNT_YTD, BAL.CREATION_DATE,
                 BAL.CREATED_BY, BAL.LAST_UPDATE_DATE, BAL.LAST_UPDATED_BY, BAL.STATUS, BAL.ANET_STATUS,
                 BAL.COG_STATUS, BAL.comb_id, BAL.MESSAGE,
                 ROW_NUMBER() OVER (ORDER BY LAST_UPDATE_DATE) rn
                 FROM   acc_balance_stg
                 WHERE  accounting_period='MAY-10')
          WHERE rn <= 100)
    SELECT *
    FROM   subq_bal bal
    ,      acc_Segments_v_tst seg
    where  BAL.NATURAL_ACCOUNT = SEG.SEGMENT_VALUE
    AND    SEG.SEGMENT_COLUMN = 'SEGMENT99';However, the parentheses you use around comb_id make me question what your intention is here in the subquery?
    Do you have multiple rows in ACC_BALANCE_STG for the same comb_id and last_update_date?
    If so you may want to do a MAX on last_update_date, group by comb_id before doing the analytic restriction.
    Edited by: DomBrooks on Jun 16, 2010 5:56 PM

  • Performance of OBIEE report whereas SQL query behind it executed in 1-2 min

    Facing lot of performance issues in OBIEE reports, whereas SQL query behind the report fetch data in 2-3 minutes. Reprot take around 1-2 hrs. Can anyone help to resolve this please?

    (my 2c worth)... if the physical query runs for a reasonably short time but the report takes much longer to return it suggests the rendering process (ie. pivot view) is lagging.
    To test this theory, go into Answers and remove all views from the request and leave a simple table view on the compound view. Run the report and the report should return around the same time the physical request takes to run because the table view is a very raw, un aggregated rendering process. Table views are nice and fast. If that works then you can focus on tuning your other views, ie. Pivot view. I've seen a simple pivot view take minutes to render what looks like a simple report because the underlying recordset is quite large.
    I hope this helped. another quick trick you could try is applying aggregation in the formulas to aggregate things at the physical sql level so the returning result set isn't 5,000. depends what you're up to with the end report.
    Edited by: user8300108 on 25-Feb-2010 04:40

Maybe you are looking for

  • Service Ticket view cannot be displayed

    Hi Experts, In the Web IC, when I try to click on the "Service Ticket" button from the navigation bar, I see the following error: Cannot display view ICCMP_BTSHEAD/BTSHeader of UI Component ICCMP_BTSHEAD An exception has occurred Exception Class  CX_

  • Final Cut Pro x10.2 training book

    Does anyone know if there is an updated training book available for this version of FCP X? I just completed a course at an approved training center, and they provided me with the training book, but I've downloaded the new FCP X 30-day trial, and ther

  • Warning when i am trying to refresh security in planning

    Hello, We are getting a Warning we are getting a warning....This is for the first time i am seeing this in Version 11. WARNING: Refresh will recreate the outline for all the Essbase cubes used in this Application based on the current metadata definit

  • Conditional Build Tags for Framesets Using RH6

    I am using RoboHelp 6. I have conditional build tags on some topics within a folder and also on certain entire folders and these are working nicely. In addition, however, I really would like to add conditional build tags to two framesets in order to

  • No matter what i try i cant reset or restore my ipod?

    Help anyone. No matter what i have tried i can nor get my ipod to recover or restore? I have tried resotring from itunes. I get error message 3014?