473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Using Case Expression-----tuning

1
Can somebody help rewrite this query using a CASE expression to make it work faster...............now the query is taking 11 minutes to fetch results......
----------------------------------------------------------------------------------------------------------
select
substr((select bu.pref_verdi from t_preferanse bu where bu.pref_id = 'OPERATION'),1,15) as BUNIT,
SUM(MMSCF_FLARE) MMSCF_FLARE, SUM(MMSCF_INJ) MMSCF_INJ, SUM(BBL_Oil_Fuel) BBL_Oil_Fuel,
SUM(MMSCF_FUEL) MMSCF_FUEL, v_year, rtrim(v_month) v_month
from
(
-- MMSCF of gas flared or vented from the field during the month
-- 1. MMSCF_FLARE
select
'' as BUNIT, SUM(NET_GAS_VOL_MSCF)/1000 MMSCF_FLARE, 0 MMSCF_INJ, 0 BBL_Oil_Fuel, 0 MMSCF_FUEL,
to_char(production_day,'YYYY') v_year, to_char(production_day,'MONTH') v_month
from
RV_CT_STRM_DAY_STREAM
where
STREAM_CATEGORY = 'GAS_FLARE'
group by
to_char(production_day,'YYYY'), to_char(production_day,'MONTH')
union
-- MMSCF of gas produced from the field and reinjected either
-- into the same field or other fields. Does not include
-- gas-lift gas
-- 2. MMSCF_INJ
select
'', 0, SUM(NET_GAS_VOL_MSCF)/1000, 0, 0, to_char(production_day,'YYYY'), to_char(production_day,'MONTH')
from
RV_CT_STRM_DAY_STREAM
where
STREAM_CATEGORY = 'GAS_INJ'
group by
to_char(production_day,'YYYY'), to_char(production_day,'MONTH')
union
-- Barrels of Oil (at standard conditions) used as fuel
-- from the field during the month
-- 3. BBL_Oil_Fuel
select
'', 0, 0, SUM(NET_OIL_VOL_BBLS), 0, to_char(production_day,'YYYY'), to_char(production_day,'MONTH')
from
RV_CT_STRM_DAY_STREAM
where
STREAM_CATEGORY = 'OIL_FUEL'
group by
to_char(production_day,'YYYY'), to_char(production_day,'MONTH')
union
-- MMSCF of gas used as fuel from the field during the month
-- 4. MMSCF_FUEL
select
'', 0, 0, 0, SUM(NET_GAS_VOL_MSCF)/1000, to_char(production_day,'YYYY'), to_char(production_day,'MONTH')
from
RV_CT_STRM_DAY_STREAM
where
STREAM_CATEGORY = 'GAS_FUEL'
group by
to_char(production_day,'YYYY'), to_char(production_day,'MONTH')
)
group by v_year, rtrim(v_month)
/
Feb 19 '07 #1
0 1073

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael Hill | last post by:
Is this a valid sql statement: SELECT case field1 when 'first' then 1 when 'second' then 1 else null end FROM mytable
2
by: Alex | last post by:
Hi folks, I'm doing calculations based on data in a table, but the data has some zeros in the field I'm dividing by. I'm trying to write a script to replace any field with 0 or null with 1, but...
10
by: Jozef de Veuster | last post by:
Hi, I'm trying to create a Stored Procedure that returns a recordset, but I want to be able to choose the ORDER BY clause in mijn parameter list of the Stored Procedure. Since CASE .. WHEN can...
12
by: rAinDeEr | last post by:
Hi, I have a table with 2 columns ** CREATE TABLE test (emp_num DECIMAL(7) NOT NULL,emp_name CHAR(10) NOT NULL) and i have inserted a number of records. ** Now, I want to insert a new...
0
by: Diego Martins | last post by:
Hi! The following code snippet: namespace { bool charCompare(char a, char b) { return tolower(a) < tolower(b); } } bool compareString(const std::string & s1, const std::string & s2) {
0
by: Deven Oza | last post by:
please help me to solve the query. (Using Case statements) Write PL/SQL code such that: the user will input a letter (A, B, C); the letter will refer to a case statement that will ask for...
0
by: GGawaran | last post by:
Did a search but couldn't find anything to answer my question. In asp, i am using an if else statement for a variable. For Example; //Declared variable// dim greg
2
by: pintu | last post by:
Hi Friends, I want to use "in" clause in case statement as shown below. e.g select * from employee where empid in case i_desgn when 'HR' then (1,2,3,4,5) when 'MD' then 1 else 7 end
2
by: carmelo | last post by:
Hello, I'm working on a DB on which I can run only SELECT commands, so I'd like to modify this UPDATE command, which makes use of CASE: update Table set field2 = case when (SUBSTR(field,1,2)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.