Help required writing a query!
Dear All,
My database is 11gR2 on Linux.
I have data like this:
ID Name
1 Mike
2 Mike Peter
3 Steven
4 Steven Andrew
In a select query I want to get the output
1 Mike
3 Steven
Logic, if it find next match for like for the first name, skip record, even if it contains second name
Kindly help.
Regards, Imran
Hi Imran,
This is defintely not a nobel price, but it returned what your specified.
WITH t1
AS (SELECT 1 AS id, 'Mike' AS name FROM DUAL UNION
SELECT 2, 'Mike Peter' FROM DUAL UNION
SELECT 3, 'Steven' FROM DUAL UNION
SELECT 4, 'Steven Andrew' FROM DUAL)
SELECT *
FROM t1
WHERE name IN (SELECT SUBSTR (name, 1, INSTR (name, ' ', 1) - 1) FROM t1)HTH,
Thierry
Similar Messages
-
Dear All,
My database is 11gR2 on Linux.
I am struck in writing a difficult query, need help from your guys.
I have a table, an application is controlling the columns of this table. Columns are added by the application.
This is the structure of the table:
create table imran_test(
2 username varchar2(100),
3 layer1 number(1),
4 layer2 number(2),
5 layer3 number(2));
-- where layer1, layer2, layer3.... are increased up to layer 22 and could be increased more...
Now each username will have 1 in any one of the layer, and all other layers will have 0
Like if I consider the above table this could be the sample data:
imran 1 0 0
hafeez 0 1 0
james 0 0 1
Now the result my query should return is:
select username, <column name where value is 1> and value of it, as per sample data, this should be return by the query:
imran layer1 1
hafeez layer2 1
james layer 3 1
Note: Please remember the columns are not fixed, they are added/altered by application.
Regards,
ImranThe table design is incorrect as it is not in 3NF and has a repeating group
You should correct the 'design' first or turn the layer... columns in a VARRAY.
Also my feeling is you should change your subject line 'Help in writing a query!' in 'Write my query' as that is what you actually ask, and leave out the exclamation mark.
Basically you dump everything in this forum, and being a bit less demanding might suit you better.
Also you still act rude by not marking your questions as answered.
Change that
Sybrand Bakker
Senior Oracle DBA
Edited by: sybrand_b on 1-apr-2012 12:09 -
Need help in writing the query
The initial data is as follows:
ID PARENT_ID
=============
1 NULL
2 NULL
3 2
4 6
5 3
6 7
7 4
8 NULL
but output is as follows in such way that Parent_Id should be displayed in ID place
ID PARENT_ID
=============
1 NULL
2 NULL
3 2
8 NULL
6 8
4 6
5 3
7 4
Can any one help how resolve this query?
Thanks in advanceYour output is inconsistent with initial data :) But
select * from t start with parent_id is null connect by parent_id = prior id; -
Hi evrybody,
I have a requirement which seems very wierd to me, I m unable to clue it also. Please help me in writing the same.
I have a column in a table which contains the data with spaces and everythng same as below:
SUBSCRIBER LINE TEST
VERSION 2
DEV SNB MP FCODE
LIBA-13 4222430012 11 3
FOREIGN VOLTAGE TESTS
DC AC
FVAE FVBE FVAB FVAE FVBE FVAB
LACC LACC 7.4 0.1 0.1 0.1
0.0 0.0 PASS PASS PASS PASS
PASS PASS
INSULATION RESISTANCE TESTS
IRAE IRBE IRABA IRBBA IRAB
LACC LACC LACC LACC 8113K
10000K >10000K >10000K >10000K PASSPASS PASS PASS PASS
CAPACITANCE MEASUREMENTS
CAE CBE CAB BRK
LACC LACC 4428 NO
68 72
NT LOOPBACK TEST
PASS
NT DC SIGNATURE TEST
V-HIGH V-LOW
83.920K LACC
PASS >10000K
PASS
NT CONNECTED
INV
CIRCUIT TEST RESULT
FAIL
I need to get the o/p as:
FVAELACC=0.0 FVBELACC=0.0 FVAB=7.4 FVAE=0.1 FVBE=0.1 FVAB=0.1
CAELACC=68 CBELACC=72 CAB=4428
NT CONNECTED=INV..
Thanks in advance.Evrybody thanks for advices. My Question is little unclear but the requirement is that itself.. Anyways I got the O/p finally.
Mr. Shahzad ,if any of the questions makes u feel like wasting ur technical time, jus donot read it.. The people who can undertsand the problem, they can answer to the post. If the requirement is like that, none of us are helpless. -
I have a table and cols as below:
START DATE TOTAL DAYS
10/11/2011 15:00 1
10/15/2011 5:00 1
12/22/2011 10:00 1
12/22/2011 11:00 2
12/30/2011 10:00 1
1/1/2012 1:00 1
1/1/2012 10:00 1
1/1/2012 16:00 2
1/2/2012 14:00 1
1/3/2012 15:00 1
1/4/2012 15:00 2
1/4/2012 18:00 1
I need to query where the values from the above table
should return values like below:
I tried many ways but could not find suitable solution.
Kindly help me in this regard.
START DATE TOTAL DAYS
10/11/2011 15:00 1
10/15/2011 5:00 1
12/22/2011 11:00 2
12/30/2011 10:00 1
1/1/2012 16:00 2
1/2/2012 14:00 1
1/3/2012 15:00 1
1/4/2012 15:00 2
ultimate goal is to sum up the all numbers TOTAL DAYS column in the second table... All task should be handled in single query. I cannot use java coding to handle this as my requirement needs to be included in the query which exists already.
Edited by: 915175 on Feb 16, 2012 11:02 PMselect trunc(start_date), max(start_date), max(total_days) from tablename
group by trunc(start_date);Please check below Test done at my local site with you data:
SQL>
SQL> with tablename as
2 (
3 select to_date('10/11/2011 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
4 select to_date('10/15/2011 5:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
5 select to_date('12/22/2011 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
6 select to_date('12/22/2011 11:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all
7 select to_date('12/30/2011 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
8 select to_date('1/1/2012 1:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
9 select to_date('1/1/2012 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
10 select to_date('1/1/2012 16:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all
11 select to_date('1/2/2012 14:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
12 select to_date('1/3/2012 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all
13 select to_date('1/4/2012 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all
14 select to_date('1/4/2012 18:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual
15 )
16 select TO_CHAR(max(start_date),'MM/DD/YYYY HH24:MI') start_date , max(total_days) total_days from tablename
17 group by trunc(start_date);
START_DATE TOTAL_DAYS
10/15/2011 05:00 1
01/03/2012 15:00 1
12/30/2011 10:00 1
01/01/2012 16:00 2
10/11/2011 15:00 1
12/22/2011 11:00 2
01/04/2012 18:00 2
01/02/2012 14:00 1
8 rows selected.
SQL>Regards,
Dipali..
Update: Added test done at my database..
Edited by: Dipali Vithalani on Feb 16, 2012 11:18 PM -
Hi,
I have a table with two columns as follows
child parent
mom grandma
daughter mom
How can I write a single query so that the result will be daughter,mom,grandma?
Thanks
Ravi.Responses to these postings will help:
pivot the column names
PIVOT in oracle.
Re: Pivot Query -
Hi,
I have a table which has columns that records the logon and logoff times of the users every thime they do so. here are the column descriptions
MSG DATE - DATE of the Logon\logoff
MSG TIME - TIME of the logon\log off
Log Type - Type of activity ( Logon or Logoff.)
User NAme
Q)My requirement is to find the users that haven't logged on in the past 6 months. Can you please help?
Many Thanks,
Bhanuselect [User Name] from LogActivity
GROUP BY [User Name]
HAVING MAX([MSG Date]) < DATEADD(month, -6, CURRENT_TIMESTAMP)
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Need help with writing a query with dynamic FROM clause
Hi Folks,
I need help with an query that should generate the "FROM" clause dynamically.
My main query is as follows
select DT_SKEY, count(*)
from *???*
where DT_SKEY between 20110601 and 20110719
group by DT_SKEY
having count(*) = 0
order by 1; The "from" clause of the above query should be generated as below
select 'Schema_Name'||'.'||TABLE_NAME
from dba_tables
where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
Any pointers will be appreciated.
Thanks
rogers42Hi,
rogers42 wrote:
Hi Folks,
I need help with an query that should generate the "FROM" clause dynamically.
My main query is as follows
select DT_SKEY, count(*)
from *???*
where DT_SKEY between 20110601 and 20110719
group by DT_SKEY
having count(*) = 0
order by 1; The "from" clause of the above query should be generated as below
select 'Schema_Name'||'.'||TABLE_NAME
from dba_tables
where OWNER = 'Schema_Name'
Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
-- Preliminary Query:
COLUMN my_table_name_col NEW_VALUE my_table_name
SELECT table_name AS my_table_name_col
FROM all_tables
WHERE owner = 'SCOTT'
AND table_name LIKE 'E%';
-- Main Query:
SELECT COUNT (*) AS cnt
FROM scott.&my_table_name
;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
Edited by: Frank Kulash on Aug 11, 2011 2:30 PM -
Help Required(Rewriting the query to reduce steps)
With and Without Group ID,I am populating a value into a column,Can anyone please help to write the same query in an other way.This is a sample column.Likewise,there are 5 more columns to be populated.So that I have to write 2 left outer joins for a single column with a little difference.
SELECT
CASE
WHEN T6.ACTUAL_FUNCTION IS NOT NULL
THEN T6.ACTUAL_FUNCTION
WHEN T10.ACTUAL_FUNCTION IS NOT NULL
THEN T10.ACTUAL_FUCNTION
ELSE T5.ACTUAL_FUCNTION
END AF_NOM_PRE_GTEES
FROM
ABC_WT17 T1
INNER JOIN
ABC_CUSTOMER_WT01 T3
ON T1.ORIGINAL_SDS_PARTY_IDR=T3.ORIGINAL_SDS_PARTY_IDR
AND T1.IDR_TYPE_CODE=T3.IDR_TYPE_CODE
LEFT OUTER JOIN /* This is the condition with group ID*/
RESIDUAL_CONTROL T6
ON
T1.NOM_PRE_GTEES = T6.VALUE_MAX
OR
T1.NOM_PRE_GTEES > T6.VALUE_GREATER_THAN
AND
T1.NOM_PRE_GTEES < T6.VALUE_MAX
AND
_ T1.GROUP_ID = T6.GROUP_ID_
AND
T6.FALLBACK_IND = ‘N’
LEFT OUTER JOIN /* this is the condition without Group ID*/
RESIDUAL_CONTROL T10
ON
T1.NOM_PRE_GTEES = T10.VALUE_MAX
OR
T1.NOM_PRE_GTEES > T10.VALUE_GREATER_THAN
AND
T1.NOM_PRE_GTEES < T10.VALUE_MAX
AND
T10.FALLBACK_IND = ‘N’
CROSS JOIN
RESIDUAL_CONTROL T5
ON T5.FALLBACK_IND = ‘Y’
Thanks in advance.KVB wrote:
With and Without Group ID,I am populating a value into a column,Can anyone please help to write the same query in an other way.This is a sample column.Likewise,there are 5 more columns to be populated.So that I have to write 2 left outer joins for a single column with a little difference.
SELECT
CASE
WHEN T6.ACTUAL_FUNCTION IS NOT NULL
THEN T6.ACTUAL_FUNCTION
WHEN T10.ACTUAL_FUNCTION IS NOT NULL
THEN T10.ACTUAL_FUCNTION
ELSE T5.ACTUAL_FUCNTION
END AF_NOM_PRE_GTEES
FROM
ABC_WT17 T1
INNER JOIN
ABC_CUSTOMER_WT01 T3
ON T1.ORIGINAL_SDS_PARTY_IDR=T3.ORIGINAL_SDS_PARTY_IDR
AND T1.IDR_TYPE_CODE=T3.IDR_TYPE_CODE
LEFT OUTER JOIN /* This is the condition with group ID*/
RESIDUAL_CONTROL T6
ON
T1.NOM_PRE_GTEES = T6.VALUE_MAX
OR
T1.NOM_PRE_GTEES > T6.VALUE_GREATER_THAN
AND
T1.NOM_PRE_GTEES < T6.VALUE_MAX
AND
_ T1.GROUP_ID = T6.GROUP_ID_
AND
T6.FALLBACK_IND = ‘N’
LEFT OUTER JOIN /* this is the condition without Group ID*/
RESIDUAL_CONTROL T10
ON
T1.NOM_PRE_GTEES = T10.VALUE_MAX
OR
T1.NOM_PRE_GTEES > T10.VALUE_GREATER_THAN
AND
T1.NOM_PRE_GTEES < T10.VALUE_MAX
AND
T10.FALLBACK_IND = ‘N’
CROSS JOIN
RESIDUAL_CONTROL T5
ON T5.FALLBACK_IND = ‘Y’
Thanks in advance.Thread: HOW TO: Post a SQL statement tuning request - template posting
HOW TO: Post a SQL statement tuning request - template posting -
Help on writing this query.
Hi Folks,
I'm trying to write a query to retrive the following information regarding snapshots. I tried lot of ways and couldn't get the solutions so seeking your help...
Can you send me a query that will give me all this information.
db name of snapshot site
snapshot name and their base table
refresh type (if it is fast, please list he snapshot log used)
refresh group which snapshot belongs to
dbms_job number which perform the refresh, job current status
refresh frequency
last refresh time
thanks
KarthikIf you tried a lot of ways ... post your work and show us what you have done.
What you are being asked to do is query data dictionary views. Do you know which ones?
SELECT view_name
FROM all_views
WHERE view_name LIKE '%<you fill this in>%';That is all the hints you get until you show your work. -
Need help in writing inline query or subquery
Hi All,
I have 4 select statements like below ,
1>Select customer_number, customer_name,customer_address1
FROM ABC
WHERE Site_use_code='BILL_TO'
2>Select customer_number, customer_name,customer_address1
FROM ABC
WHERE Site_use_code='SHIP_TO'
3>Select customer_number, customer_name,customer_address1
FROM ABC
WHERE Site_use_code='SOLD_TO'
I need to write all these 3 in single select statement in such a way that if any select statement doesnot return any data it should execute the other select statements means it should not fail.
for each column of the select statment i can write separate select statements in that way it should work but the query should be very big.
So please help me on thsi.
ThanksExample of my solution:
SQL> ed
Wrote file afiedt.buf
1 with t as (
2 select 1 as customer_number, 'Fred' as customer_name, 'address1' as customer_address1, 'BILL_TO' as site_use_code from dual union all
3 select 1 as customer_number, 'Fred' as customer_name, 'address1' as customer_address1, 'SHIP_TO' as site_use_code from dual union all
4 select 2 as customer_number, 'Bob' as customer_name, 'address2' as customer_address1, 'BILL_TO' as site_use_code from dual union all
5 select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'BILL_TO' as site_use_code from dual union all
6 select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'SHIP_TO' as site_use_code from dual union all
7 select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'SOLD_TO' as site_use_code from dual union all
8 select 4 as customer_number, 'Tim' as customer_name, 'address4' as customer_address1, 'BILL_TO' as site_use_code from dual union all
9 select 5 as customer_number, 'Sam' as customer_name, 'address5' as customer_address1, 'BILL_TO' as site_use_code from dual
10 )
11 --
12 -- END OF TEST DATA
13 --
14 select customer_number
15 ,customer_name
16 ,customer_address1
17 ,site_use_code
18 from (
19 select customer_number
20 ,customer_name
21 ,customer_address1
22 ,site_use_code
23 ,row_number() over (partition by customer_number order by decode(Site_use_code,'BILL_TO',1,'SHIP_TO',2,3) desc) as rn
24 FROM t
25 WHERE Site_use_code IN ('BILL_TO','SHIP_TO','SOLD_TO')
26 )
27* where rn = 1
SQL> /
CUSTOMER_NUMBER CUSTOM CUSTOMER SITE_US
1 Fred address1 SHIP_TO
2 Bob address2 BILL_TO
3 George address3 SOLD_TO
4 Tim address4 BILL_TO
5 Sam address5 BILL_TO
SQL>Or alternative...
SQL> ed
Wrote file afiedt.buf
1 with t as (
2 select 1 as customer_number, 'Fred' as customer_name, 'address1' as customer_address1, 'BILL_TO' as site_use_code from dual union all
3 select 1 as customer_number, 'Fred' as customer_name, 'address1' as customer_address1, 'SHIP_TO' as site_use_code from dual union all
4 select 2 as customer_number, 'Bob' as customer_name, 'address2' as customer_address1, 'BILL_TO' as site_use_code from dual union all
5 select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'BILL_TO' as site_use_code from dual union all
6 select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'SHIP_TO' as site_use_code from dual union all
7 select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'SOLD_TO' as site_use_code from dual union all
8 select 4 as customer_number, 'Tim' as customer_name, 'address4' as customer_address1, 'BILL_TO' as site_use_code from dual union all
9 select 5 as customer_number, 'Sam' as customer_name, 'address5' as customer_address1, 'BILL_TO' as site_use_code from dual
10 )
11 --
12 -- END OF TEST DATA
13 --
14 select distinct
15 customer_number
16 ,customer_name
17 ,customer_address1
18 ,first_value(site_use_code) over (partition by customer_number order by decode(Site_use_code,'BILL_TO',1,'SHIP_TO',2,3) desc) as site_use_code
19 FROM t
20 WHERE Site_use_code IN ('BILL_TO','SHIP_TO','SOLD_TO')
21* order by customer_number
SQL> /
CUSTOMER_NUMBER CUSTOM CUSTOMER SITE_US
1 Fred address1 SHIP_TO
2 Bob address2 BILL_TO
3 George address3 SOLD_TO
4 Tim address4 BILL_TO
5 Sam address5 BILL_TO -
Hi need help in writing this query
A table has three columns - id (primary key), categoryID (numeric) and
amount (numeric). The goal is to provide a query that would show categoryID
and sum of amounts within that category where categoryID is an odd number
and sum of amounts is greater than 100,000select categoryid,sum(amount) from table where mod(categoryid,2)=1
group by categoryid
having sum(amount) > 100000
Regards,
Yuri
[http://it.toolbox.com/blogs/living-happy-oracle] -
sir
below query runs fine
but the probblem is...i am not able to display the figures in the format '999999.99'
Also please guide me as to make the query short... can i use cursors here?
i am using 10g
select
LBRCODE branch,
trim(substr(PRDACCTID,1,8)) product,
sum(case when totsanclimit between 0 and 200000 then
(Case when hrk in (13,14) THEN
(CASE WHEN bal4 !=0 THEN 1 else 0 END )
ELSE
(CASE WHEN BAL1-(BAL4-BAL5)!=0 THEN 1 ELSE 0 END)
END )
else 0 end )as "bktCount-1",
SUM( CASE WHEN TOTSANCLIMIT between 0 and 200000 then
(Case when hrk in (13,14) THEN
to_number(to_char(bal4,'99999999999.99'))
else
to_char(BAL1,'99999999999.99')-(to_char(BAL4,'99999999999.99')-to_char(BAL5,'99999999999.99'))
END )
ELSE
0 end) AS"Bkt_1",
sum(case when totsanclimit between 200001 and 1000000 then
(Case when hrk in (13,14) THEN
(CASE WHEN bal4 !=0 THEN 1 else 0 END )
ELSE
(CASE WHEN BAL1-(BAL4-BAL5)!=0 THEN 1 ELSE 0 END)
END )
else 0 end )as "bktCount-2",
SUM(
CASE WHEN TOTSANCLIMIT between 200001 and 1000000
then
(Case when hrk in (13,14) THEN
to_number(to_char(bal4,'99999999999.99'))
else
to_char(BAL1,'99999999999.99')-(to_char(BAL4,'99999999999.99')-to_char(BAL5,'99999999999.99'))
END )
ELSE 0 end) AS"Bkt_2",
sum(case when totsanclimit between 1000001 and 5000000 then
(Case when hrk in (13,14) THEN
(CASE WHEN bal4 !=0 THEN 1 else 0 END )
ELSE
(CASE WHEN BAL1-(BAL4-BAL5)!=0 THEN 1 ELSE 0 END)
END )
else 0 end )as "bktCount-3",
SUM(
CASE WHEN TOTSANCLIMIT between 1000001 and 5000000
then
(Case when hrk in (13,14) THEN
to_number(to_char(bal4,'99999999999.99'))
else
to_char(BAL1,'99999999999.99')-(to_char(BAL4,'99999999999.99')-to_char(BAL5,'99999999999.99'))
END )
ELSE 0 end) AS"Bkt_3",
sum(case when totsanclimit between 5000001 and 10000000 then
(Case when hrk in (13,14) THEN
(CASE WHEN bal4 !=0 THEN 1 else 0 END )
ELSE
(CASE WHEN BAL1-(BAL4-BAL5)!=0 THEN 1 ELSE 0 END)
END )
else 0 end )as "bktCount-4",
SUM(
CASE WHEN TOTSANCLIMIT between 5000001 and 10000000
then
(Case when hrk in (13,14) THEN
to_number(to_char(bal4,'99999999999.99'))
else
to_char(BAL1,'99999999999.99')-(to_char(BAL4,'99999999999.99')-to_char(BAL5,'99999999999.99'))
END )
ELSE 0 end) AS"Bkt_4",
sum(case when totsanclimit BETWEEN 10000001 AND 200000000 then
(Case when hrk in (13,14) THEN
(CASE WHEN bal4 !=0 THEN 1 else 0 END )
ELSE
(CASE WHEN BAL1-(BAL4-BAL5)!=0 THEN 1 ELSE 0 END)
END )
else 0 end )as "bktCount-5",
SUM(
CASE WHEN TOTSANCLIMIT BETWEEN 10000001 AND 200000000
then
(Case when hrk in (13,14) THEN
to_number(to_char(bal4,'99999999999.99'))
else
to_char(BAL1,'99999999999.99')-(to_char(BAL4,'99999999999.99')-to_char(BAL5,'99999999999.99'))
END )
ELSE 0 end) AS"Bkt_5",
sum(case when totsanclimit > 200000000 then
(Case when hrk in (13,14) THEN
(CASE WHEN bal4 !=0 THEN 1 else 0 END )
ELSE
(CASE WHEN BAL1-(BAL4-BAL5)!=0 THEN 1 ELSE 0 END)
END )
else 0 end )as "bktCount-6",
SUM(
CASE WHEN TOTSANCLIMIT > 200000000
then
(Case when hrk in (13,14) THEN
to_number(to_char(bal4,'99999999999.99'))
else
to_char(BAL1,'99999999999.99')-(to_char(BAL4,'99999999999.99')-to_char(BAL5,'99999999999.99'))
END )
ELSE 0 end) AS"Bkt_6",
--total
sum(
(Case when hrk in (13,14) THEN
(CASE WHEN bal4 !=0 THEN 1 else 0 END )
ELSE
(CASE WHEN BAL1-(BAL4-BAL5)!=0 THEN 1 ELSE 0 END)
end)
)as "TotCount-7",
SUM((Case when hrk in (13,14) THEN
to_number(to_char(bal4,'99999999999.99'))
else
to_char(BAL1,'99999999999.99')-(to_char(BAL4,'99999999999.99')-to_char(BAL5,'99999999999.99'))
END )
) AS"Total"
from
select
q1.lbrcode,q1.prdacctid,q1.totsanclimit,q2.balance1,balance3,balance4,balance5,balance6,balance7,q3.hrk
FROM
SELECT LBRCODE,PRDACCTID,SANCDATE,TOTSANCLIMIT,RNK FROM
SELECT
LBRCODE,
PRDACCTID,
EFFFROMDATE,
CURCD,
PLRLINKYN,
SANCAUTHORITY,
SANCDATE,
TOTSANCLIMIT,
RANK() OVER (PARTITION BY LBRCODE,PRDACCTID ORDER BY EFFFROMDATE DESC) AS RNK
FROM LIMIT_MAST
WHERE LBRCODE IN (3)
-- AND PRDACCTID LIKE 'PLLN %'
WHERE RNK=1
)Q1,
(SELECT LBRCODE,PRDACCTID,CBLDATE,BALANCE1,BALANCE2,BALANCE3,BALANCE4,BALANCE5,BALANCE6,BALANCE7 FROM
( SELECT TRN_MAST.*,
RANK() OVER(PARTITION BY LBRCODE,PRDACCTID ORDER BY CBLDATE DESC) AS HRK
FROM TRN_MAST
WHERE CBLDATE <= TO_DATE('31-MAR-2008','DD-MON-RR')
AND (LBRCODE,TRIM(SUBSTR(PRDACCTID,1,8))) IN (SELECT LBRCODE,TRIM(PRDCD) FROM PRD_MAST
WHERE MODULETYPE IN (13,14,30))
)WHERE HRK=1
)Q2,
( SELECT LBRCODE,TRIM(PRDCD) prd,MODULETYPE hrk FROM PRD_MAST
WHERE (LBRCODE,TRIM(PRDCD)) IN
(SELECT LBRCODE,TRIM(SUBSTR(PRDACCTID,1,8)) FROM LIMIT_MAST)
)q3
WHERE Q1.LBRCODE=Q2.LBRCODE
AND Q1.PRDACCTID=Q2.PRDACCTID
AND TRIM(SUBSTR(Q2.PRDACCTID,1,8))=q3.PRD
AND Q1.LBRCODE=q3.LBRCODE
group by lbrcode,trim(substr(prdacctid,1,8))
order by lbrcode
/Like this?
SQL> select 123456 my_num from dual;
MY_NUM
123456
SQL>
SQL> column my_num format 999999.99
SQL>
SQL> select 123456 my_num from dual;
MY_NUM
123456.00
SQL>Asif Momen
http://momendba.blogspot.com -
Hi,
I was given a task of changing the existing query the COPA.
I want to aggregate the last three months data into a single month.
Any suggestions for doing so.
Thanks,Hi Murali,
Can u be more specific on how to do it?
My report is in crystal and the source for tht is BW?
So ny suggetions. -
Hi,
I am sure this is not a very complex query but i am out of ideas today and so decided to post it. Here is my SQL:
select cr.id, ri.report_name
from category cr, report ri where ri.report_id = cr.id
and
cr.id in ('AC01','UP01','UP02','UP03','XD01','UP04','ED01','EB01','ES01','DL01','UV01');
I would like my output to appear in the same format as is specified in the IN clause i.e. first 'AC01' then 'UP01' then 'UP02' then 'UP03' and so forth.
Thanks in advance.Then your order by should be like this
ORDER BY DECODE(cr.id, 'AC01', 1, 'UP01', 2, 'UP02', 3, 'UP03', 4, 'XD01', 5, 'UP04', 6, 'ED01', 7, 'EB01', 8, 'ES01', 9, 'DL01', 10, 'UV01', 11)
Maybe you are looking for
-
Error message - media being played is of an unsupported format
This is a known issue that is a pain in the butt. Your media player is locked up as well. Look here: http://www.blackberry.com/btsc/microsites/search.do?cmd=displayKC&docType=kc&externalId=KB20612&slic... 0 522224469
-
Check point not complete - Production issue
Hi There is a error in my alert log that checkpoint not complete .(Oracle Database 10g Release 10.2.0.4.0) and when i checked select name, checkpoint_change#, to_char(checkpoint_time, 'DD.MM.YYYY HH24:MI:SS') from v$datafile_header ; it shows NAME CH
-
Will I be happy with a iMac?
I currently have a DC G5 2.3 with 2.5 gigs of ram. I want to upgrade to a intel machine so I can also run windows for flight simulator X . On the mac side I run Abobe creative suite 3 mostly running Photoshop. I also have a MBP 2.4, which runs Photos
-
After changing the black ink cartridge on my Cannon MG3100, when I print word and from the internet the prints are all misaligned and I have manually done the print head alignment, print alignment values, cleaned the nozzles, cleaned elements and cle
-
MOV files become 'invisible' in a project after upgrading FCP and OS
After I have installed the last FCP update (10.0.8), and Mountain Lion, some files of an event became 'invisible' in a project. Those files are MOV-files (originally shot on Panasonoc GH3 in MOV format). Few files only turned to be invisible in the t