How to use CASE.
I am trying to use the function case but not sure what I am missing.
Can someone please let me know where im going wrong with the following query?
SELECT location_id,
CASE
WHEN cost < 1 THEN count(target_id) ELSE 0
END '< 1'
CASE
WHEN cost BETWEEN 1 AND 2.99 THEN count(target_id) ELSE 0
END '1 - 2.99'
CASE
WHEN cost BETWEEN 3 AND 4.99 THEN count(target_id) ELSE 0
END '3 - 4.99'
CASE
WHEN cost BETWEEN 5 AND 6.99 THEN count(target_id) ELSE 0
END '5 - 6.99'
CASE
WHEN cost >7 THEN count(target_id) ELSE 0
END '>= 7'
FROM
SELECT
FROM
targets t
LEFT OUTER JOIN
information i
ON
t.target_id=i.target_id
LEFT OUTER JOIN
access_cost ac
ON
i.security_level BETWEEN ac.lower_BOUND_LEVEL AND ac.upper_BOUND_LEVEL
)
Well dear right now, I am feeling very sleepy not in mood to fire these query against DB, but I guess you are trying to get the results in Bucket, all you are missing here is comma(,)
Let me correct your query
Your Query
SELECT location_id,
CASE
WHEN cost < 1 THEN count(target_id) ELSE 0
END '< 1'
CASE
WHEN cost BETWEEN 1 AND 2.99 THEN count(target_id) ELSE 0
END '1 - 2.99'
CASE
WHEN cost BETWEEN 3 AND 4.99 THEN count(target_id) ELSE 0
END '3 - 4.99'
CASE
WHEN cost BETWEEN 5 AND 6.99 THEN count(target_id) ELSE 0
END '5 - 6.99'
CASE
WHEN cost >7 THEN count(target_id) ELSE 0
END '>= 7'
It should be something like
SELECT location_id,
CASE
WHEN cost < 1 THEN count(target_id) ELSE 0
END '< 1',
CASE
WHEN cost BETWEEN 1 AND 2.99 THEN count(target_id) ELSE 0
END '1 - 2.99',
CASE
WHEN cost BETWEEN 3 AND 4.99 THEN count(target_id) ELSE 0
END '3 - 4.99',
CASE
WHEN cost BETWEEN 5 AND 6.99 THEN count(target_id) ELSE 0
END '5 - 6.99',
CASE
WHEN cost >7 THEN count(target_id) ELSE 0
END '>= 7'
Hope this works...
Similar Messages
-
How to use case function in where clause
Hi,
Suppose a table DEMO has columns
DEMO TABLE
user_id
user_name
location
In this table i have 15 users. but out of 15 users i want to use only 5 users for passing as user_name.
then how to achieve the result
1. when i pass the particular 5 user_name in where clause then i should get all the user_name and for other 10 users it will show only the passing user_name.
how to use case functionDo you mean this ?
SQL> var name varchar2(10)
SQL> exec :name := 'ALLEN'
PL/SQL procedure successfully completed.
SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
2 else :name end = ename;
ENAME
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected.
SQL> exec :name := 'SMITH'
PL/SQL procedure successfully completed.
SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
2 else :name end = ename;
ENAME
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected.
SQL> exec :name := 'BLAKE'
PL/SQL procedure successfully completed.
SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
2 else :name end = ename;
ENAME
BLAKERgds. -
How to use CASE statement in WDA
Hi All,
Can any one Please expain me ' How to use CASE statement in Web dynpro ABAP? '
Please give me an example also.
Thanks in Advance !Hi,
The usage of case statement in webdynpro is same as used in general ABAP.
Data: l_id type string.
l_id = wdevent->get_string( 'ID' ).
case l_id.
when 'BTN1'.
when 'BTN2'.
when 'OTHERS'.
endcase.
Regards,
Radhika. -
How to use CASE stmt in Where clause
Hi,
How to use CASE stmt in WHERE clause?. I need the code. Please send me as early as possible..........Hi,
1004977 wrote:
Hi,
How to use CASE stmt in WHERE clause?. There's no difference between how a CASE expression is used in a WHERE clause, and how it is used in any other clause. CASE ... END always returns a single scalar value, and it can be used almost anywere a single scalar expression (such as a column, a literal, a single-row function, a + operation, ...) can be used.
CASE expressions aren't needed in WHERE clauses very much. The reason CASE expressions are so useful is that they allow you to do IF-THEN-ELSE logic anywhere in SQL. The WHERE clause already allows you to do IF-THEN-ELSE logic, usually in a more convenient way.
I need the code.So do the peple who want t help you. Post a query where you'd like to use a CASE expression in the WHERE clause. Post CREATE TABLE and INSERT statements for any tables used unless they are commonly available, such as scott.emp). Also, post the results you want from that sample data, and explain how you get those resuts from that data.
See the forum FAQ {message:id=9360002}
Please send me as early as possible..........As mentioned bfore, that's rude. It's also self-defeating. Nobody will refuse to help you because you don't appear pushy enough, but some people will refuse to help you if you appear too pushy. -
How to use case when function to calculate time ?
Dear All,
May i know how to use case when function to calculate the time ?
for the example , if the First_EP_scan_time is 12.30, then must minus 30 min.
CASE WHEN FIRSTSCAN.EP_SHIFT <> 'R1' AND FIRSTSCAN.EP_SHIFT <> 'R2'
THEN ROUND(CAST((DATEDIFF(MINUTE,CAST(STUFF(STUFF((CASE WHEN SHIFTCAL.EP_SHIFT = 'N1'
THEN CONVERT(VARCHAR(8),DATEADD(DAY,+1,LEFT(FIRSTSCAN.EP_SCAN_DATE ,8)),112) + ' ' + REPLACE(CONVERT(VARCHAR(8),DATEADD(HOUR,+0,SHIFTDESC.EP_SHIFT_TIMETO + ':00'),108),':','')
ELSE LEFT(FIRSTSCAN.EP_SCAN_DATE ,8) + ' ' + REPLACE(CONVERT(VARCHAR(8),DATEADD(HOUR,+0,SHIFTDESC.EP_SHIFT_TIMETO + ':00'),108),':','') END),12,0,':'),15,0,':') AS DATETIME),CAST(STUFF(STUFF(LASTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME)) / 60.0 - 0.25) AS FLOAT),2)
ELSE ROUND(CAST((DATEDIFF(MINUTE,CAST(STUFF(STUFF(FIRSTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME),CAST(STUFF(STUFF(LASTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME)) / 60.0) AS FLOAT),2) END AS OTWORK_HOURDo not use computations in a declarative language. This is SQL and not COBOL.
Use a table of time slots set to one more decimal second of precision than your data. You can now use temporal math to add it to a DATE to TIME(1) get a full DATETIME2(0). Here is the basic skeleton.
CREATE TABLE Timeslots
(slot_start_time TIME(1) NOT NULL PRIMARY KEY,
slot_end_time TIME(1) NOT NULL,
CHECK (start_time < end_time));
INSERT INTO Timeslots --15 min intervals
VALUES ('00:00:00.0', '00:14:59.9'),
('00:15:00.0', '00:29:59.9'),
('00:30:00.0', '00:44:59.9'),
('00:45:00.0', '01:00:59.9'),
('23:45:00.0', '23:59:59.9');
Here is the basic query for rounding down to a time slot.
SELECT CAST (@in_timestamp AS DATE), T.start_time
FROM Timeslots AS T
WHERE CAST (@in_timestamp AS TIME)
BETWEEN T.slot_start_time
AND T.slot_end_time;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
How to use CASE or DECODE in this?
Hi , I have a query like this
AND ...smthng
AND --smtg
AND age BETWEEN ....For the last AND clause for age column, I have the values passed from IN param of this SP in form of strings
'0-30', '31-60', '61-90', and '91+'. The IN param is of course VARCHAR2.
What I want to do in this AND clause
e.g. for age range '0-30', the AND clause should be
AND age BETWEEN ( if this range is '0-30' then ) 0 AND 30 ( if range is '31-60') then BETWEEN 31 AND 60.. and so on...
However this BETWEEN will work till 61-90 range but for 91+ , there is no upper bound so it should be
AND age>91
Now , i am not sure how to achieve this both BETWEEN and '>' clauses in the same AND statement.
DECODE will not work and am not sure how to use the CASE in this situation as even that can not solve this issue.
Dont want to make the last AND clause dynamic
Please suggest me how to do this.
Thanks,
Aashish
Edited by: Aashish S. on Oct 21, 2011 6:01 PMA third alternative would be to choose a suitably large value as a high end for the 91+ group and use something like:
age between to_number(CASE WHEN instr(:param, '+') = 0
THEN substr(:param, 1, instr(:param, '-') -1)
ELSE substr(:param, 1, instr(:param, '+') -1) end) and
to_number(CASE WHEN instr(:param, '+') = 0
THEN substr(:param, instr(:param, '-') +1)
ELSE '9999' END)John -
How to use case when in Select qry?
Hi Friends,
I want to use Case when in Select qry, my situation is like this
SELECT bmatnr blgort bj_3asiz bmat_kdauf b~mat_kdpos
SUM( ( case when bshkzg = 'S' then bmenge else 0 END ) -
( case when bshkzg = 'H' then bmenge else 0 END ) ) AS qty
INTO corresponding fields of table it_projsal
FROM mseg AS b
INNER JOIN mkpf AS a ON bmblnr = amblnr
AND bmandt = amandt
WHERE abudat < '20061201' AND blgort IN ('1050')
and b~mandt = '350'
GROUP BY bmatnr bj_3asiz bmat_kdauf bmat_kdpos b~lgor
If we give like this it gives an error.
Please help me, how to use or handle in select qry itself.
Regards
Shankarthis is not a way to select data from the DB tables.
first get all the data from the DB tables then u have to do SUM Ups .
Regards
prabhu -
How to use, Case function and Filter in Column Formula?
Hello All,
I am using case function and also would like to filter value to populate.
Below is showing error :
case
when '@{Time}' = 'Year' then "Time"."Fiscal Year"
when '@{Time}' = 'Quarter' then "Time"."Fiscal Quarter"
when '@{Time}' = 'Month' then FILTER ("Time"."Fiscal Period" USING "Time"."Fiscal Period" NOT LIKE 'A%')
else ifnull('@{Time}','Selection Failed') end
Thanks, AKwhen '@{Time}' = 'Month' then FILTER ("Time"."Fiscal Period" USING "Time"."Fiscal Period" NOT LIKE 'A%')I dont think Filter this works here or any other data types except number.
Try to use option Column's->Filter->Advanced->Convert this filter to SQL
If helps mark -
How to use case when statements in ODI
I need to put conditional logic before DVM look up in ODI. In the expression editor I put the following statement:-
CASE WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS' THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME=EBIZ_CELL.CELL_DATA
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC' THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)=EBIZ_CELL.CELL_DATA
END
It did not work,
Under Operators ->All Executions, found the error:-
905 : 42000 : java.sql.SQLException: ORA-00905: missing keyword
The description in Session Task contained:-
select
C1_JOURNAL_TEMPL
from APPS.POC_JOURNAL_TEMP_SOURCE_TBL POC_JOURNAL_TEMP_SOURCE_TBL, APPS.C$_0POC_JOURNAL_TEMP_TARGET_TB
where
(1=1)
And (CASE
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS'
THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME=C2_CELL_DATA
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC'
THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)=C2_CELL_DATA
END)
Checked the above code in PL/SQL Developer but it gave errors.
In PL/SQL developer tried to check a simple query using case-when but even that is giving errors in the case-when portion.
The query is as follows:-
select phase_code, accounting_period, sum(eff_cc) as BD_Eff_QTD
from prj_detail
where
case POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
when 'EXT'
then
1
when 'RAC'
then
2
when 'XXX'
then
3
else
end
I would like to know what is wrong with the above code.
Please let me know what is the correct way of using case-when in PL/SQL as well as in ODI.Your ODI case statement and PL/SQL Case statement both looks confusing.
You are writing case statement under where clause which is not a good practise. If you want to implement logic like-
select a,b,c from <table>
where
when cond^n^ 1 then do 1
when cond^n^ 2 then do 2
then better you seperate your query for each filter and do a union, in other words-
select a,b,c from <table>
where cond^n^ 1
union
select a,b,c from <table>
where cond^n^ 2
If you are writing case staement to retrieve a value/column (EBIZ_CELL.CELL_DATA) then no need to include it under filter.
ODI case for column EBIZ_CELL.CELL_DATA will be:
CASE
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS'
THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC'
THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)
END
Pl/SQL query-
select phase_code, accounting_period,
case POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
when 'EXT'then 1
when 'RAC' then 2
when 'XXX' then 3
else 'default value' --- (if no else needed then can also remove else part)
end,
sum(eff_cc) as BD_Eff_QTD
from prj_detail
Suggested as per what is understood, hope it helps.
Edited by: 939451 on Jul 5, 2012 12:47 AM
Edited by: 939451 on Jul 5, 2012 12:48 AM -
How to use case to replace the & in select statement
Oracle version : 11.1.0.6.0
RHEL
Hi,
I want to get a list of all expired and locked users but want to replace the "&" with and here is my code but it isn't working.
Please some guidance, thanks.
SQL> select username,
2 case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
3 ELS 'no locked users'
4 end) account_status
5 from dba_users
6 where account_status like 'EXPI%';
case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
ERROR at line 2:
ORA-00907: missing right parenthesis798188 wrote:
thanks for the comments I corrected the ELSE and 'EPX%' but still same error :
EOH> select username,
2 case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
3 ELSE 'no locked users'
4 end) account_status
5 from dba_users
6 where account_status like 'EXP%';
case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
ERROR at line 2:
ORA-00907: missing right parenthesisFirst of all, you do not need a CASE statement.
Did you see the where clause of your query??
6 where account_status like 'EXP%';do you realise that your query will always return those records for which value of account_status column starts with 'EXP'?
Why use CASE when it could be simply written like this :
SELECT username,
'EXPIRED AND LOCKED'
FROM dba_users
WHERE account_status LIKE 'EXP%' -
How to use case and decode to extract the data
Hello PL/SQL Gurus,
I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version
I have a table in following format -
drop table TT2;
create table TT2(College, Class,gender,status,fees) as select
'IITB','MBA','M','P',255600 from dual union all select
'IITK','MTech','M','P',300000 from dual union all select
'IITD','MBA','F','P',450000 from dual union all select
'IITKH','MBA','F','P',350000 from dual union all select
'IITC','MTech','F','P',420000 from dual union all select
'IITB','MTech','M','P',185000 from dual union all select
'IITC','MTech','M','P',235000 from dual union all select
'IITD','MBA','F','F',175000 from dual union all select
'IITM','MBA','M','F',257000 from dual union all select
'IITKH','MTech','F','P',335000 from dual union all select
'IITD','MBA','F','P',540335 from dual union all select
'IITC','MBA','F','F',125089 from dual union all select
'IITD','MTech','M','P',290756 from dual union all select
'IITM','MBA','M','P',200000 from dual union all select
'IITKH','MBA','F','F',534990 from dual union all select
'IITD','MBA','F','P',221000 from dual ;some of the extraction conditions are as following -
CASE CONDITION
College in 'IITB' and status='P'- 'WestRegion Passed'
College in 'IITC' and status='P'- 'SouthRegion Passed'
College in 'IITD' and 'IITK' and status='P' and Gender='F' - 'NothRegion Female Passed'
College not in 'IITK' and status='F' - 'Ex Kanpur Failed'
Expected output -
Region Statnding Fees
WestRegion Passed 440460
SouthRegion Passed 655000
NothRegion Female Passed 1386335
Ex Kanpur Failed 1092079SQL Used
I am using the following query which only make sure of case but this is not how i want the output , if i try to use the case within decode then how to work on this -
SELECT (CASE WHEN College in ('IITB') and status='P' then sum(fees) else 0 end) WP,
(case when College in ('IITC') and status='P' then sum(fees) else 0 end) SP,
(case when College in ('IITD','IITK') and gender='F' and status='P' then sum(fees) else 0 end) NFP,
(case when College in ('IITK') and status='F' then sum(fees) else 0 end) ExKF
FROM
TT2
GROUP BY College, Class,gender,statususer555994 wrote:
Thank you so much jeneesh i am really thankful to you ...vov.
one more query in case if any of the selection don't have the output data , then values will be displayed like -One way..
with t as
--"Add all your descriptions
(select 'WestRegion Passed' region_standing from dual union all
select 'SouthRegion Passed' region_standing from dual union all
select 'NothRegion Female Passed' region_standing from dual union all
select 'Ex Kanpur Failed' region_standing from dual)
select region_standing,sum(fees) fees
from (
(SELECT CASE WHEN College in ('IITB') and status='P'
then 'WestRegion Passed'
when College in ('IITC') and status='P'
then 'SouthRegion Passed'
when College in ('IITD','IITK') and gender='F' and status='P'
then 'NothRegion Female Passed'
when College in ('IITK') and status='F'
then 'Ex Kanpur Failed'
else 'Others' end region_standing,
sum(fees) fees
FROM TT2
GROUP BY CASE WHEN College in ('IITB') and status='P'
then 'WestRegion Passed'
when College in ('IITC') and status='P'
then 'SouthRegion Passed'
when College in ('IITD','IITK') and gender='F' and status='P'
then 'NothRegion Female Passed'
when College in ('IITK') and status='F'
then 'Ex Kanpur Failed'
else 'Others' end
union all
select region_standing,0
from t
group by region_standing;
REGION_STANDING FEES
Others 2567835
NothRegion Female Passed 1211335
WestRegion Passed 440600
Ex Kanpur Failed 0
SouthRegion Passed 655000
{code}
Edited by: jeneesh on Nov 5, 2012 5:07 PM -
How to use CASE in an update ?
I did so and an error happened:
UPDATE TB_FUNCIONARIO SET NIVEL =
CASE WHEN CARGO = 'PROGRAMADOR' AND SALARIO BETWEEN 4000 AND 8000 THEN 'PLENO'
WHEN CARGO = 'PROGRAMADOR' AND SALARIO <= 2000 THEN 'JUNIOR'
ELSE 'SENIOR' END
how to solve ?
Edited by: 995757 on 23/03/2013 13:29Ok, Solved
-
How to use CASE with UPDATE?
Hi all. I'm trying to update multiple rows in a MS-Access
database using a single query, with different values for each row.
Here's a simplified example of the code:
<cfquery name="JustInCase" datasource="variables.DB">
Update Users
SET First_Name =
CASE WHEN ID = 1 THEN 'Nini' END,
SET Last_Name
CASE WHEN ID = 32 THEN 'Yumpi' END
</cfquery>
Trying to run something like this produces the following
error message:
[Macromedia][SequeLink JDBC Driver][ODBC
Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error
(missing operator) in query expression 'CASE WHEN ID = 1 THEN
'Nini' END'.
I realize this can easily be done using multiple queries, but
the actual code will contain many updates, and I would like to at
least test the possibility of improving performance using a single
query instead of multiple queries. I would greatly appreciate any
help with this - I've been trying all kinds of variations, and
nothing seems to satisfy emperor ColdFusion. Any ideas?Case might be a verity tag but it is also a valid sql keyword
in many dbs. I use it in select clauses frequently and have seen it
used in where clauses.
The problem with the original query is that, it the value of
id is not 1, this part
SET First_Name =
CASE WHEN ID = 1 THEN 'Nini' END,
will cause a syntax error. For those values of 1 and 32, this
syntax will run, but will update every row in the table which might
not be the plan.
update users
set
case when id = 1 then first_name = 'Nini'
when id = 32 then last_name = 'Yumpi'
else first_name = first_name
end
ranger, your code will also fail if the value is neither 1
nor 32. You need a default case. -
Help: How to use Case statement in Interface ODI11g?
Hi
From my Source base i am getting 'Year' Values and i want translate these values into a code in interface and after translate want to push to Target system.
Example:
From source Database i am getting value for
Year
2010
2011
2012
When i get Year 2010 i want to modify value into 'FY10'
when i get Year 2011 i want to modify value into 'FY11'
and same for Year 2012 TO 'FY12'
I was trying to do by Case statement but didn't got success.
I dont want to create Lookup table in source system.
Any help in this regards.
Thanks
Regards
Sher
Edited by: Sher Ullah Baig on Aug 26, 2012 5:52 PMCASE
WHEN source_column='2010' THEN 'FY10'
WHEN source_column='2011' THEN 'FY11'
WHEN source_column='2012' THEN 'FY12'
END -
Help with the SQL Query: How to use case.
Q:- I have written a query which will written the following output.
C1 C2 C3
a ---- b.1 ---- 1
a ---- b.1 ---- 1
a ---- b.1 ---- 2
a ---- b.1 ---- 3
a ---- b.1 ---- 3
a ---- b.2 ---- 1
a ---- b.2 ---- 2
a ---- b.2 ---- 2
a ---- b.3 ---- 1
ac---- b.1 ---- 1
ac---- b.1 ---- 2
ac---- b.2 ---- 1
ac---- b.2 ---- 2
ac---- b.2 ---- 3
ac---- b.2 ---- 3
ac---- b ---- 1
But i want the output to print in the following way. Please suggest.
C1 C2 C3
a ---- b.1 ---- 1
------------------2
------------------3
a ---- b.2 ---- 1
------------------2
a ---- b.3 ---- 1
ac---- b.1 ---- 1
------------------2
ac---- b.2 ---- 1
------------------2
ac---- b.2 ---- 3
ac---- b ---- 1
Edited by: user555994 on Jan 18, 2011 1:42 AM
Edited by: user555994 on Jan 18, 2011 1:43 AMOr may be
SQL> ed
Wrote file afiedt.buf
1 WITH sample_data AS
2 (SELECT 'a' C1,'b.1' C2, 1 C3 FROM dual UNION ALL
3 SELECT 'a' C1,'b.1' C2, 1 C3 FROM dual UNION ALL
4 SELECT 'a' C1,'b.1' C2, 2 C3 FROM dual UNION ALL
5 SELECT 'a' C1,'b.1' C2, 3 C3 FROM dual UNION ALL
6 SELECT 'a' C1,'b.1' C2, 3 C3 FROM dual UNION ALL
7 SELECT 'a' C1,'b.2' C2, 1 C3 FROM dual UNION ALL
8 SELECT 'a' C1,'b.2' C2, 2 C3 FROM dual UNION ALL
9 SELECT 'a' C1,'b.2' C2, 2 C3 FROM dual UNION ALL
10 SELECT 'a' C1,'b.3' C2, 1 C3 FROM dual UNION ALL
11 SELECT 'ac' C1,'b.1' C2, 1 C3 FROM dual UNION ALL
12 SELECT 'ac' C1,'b.1' C2, 2 C3 FROM dual UNION ALL
13 SELECT 'ac' C1,'b.2' C2, 1 C3 FROM dual UNION ALL
14 SELECT 'ac' C1,'b.2' C2, 2 C3 FROM dual UNION ALL
15 SELECT 'ac' C1,'b.2' C2, 3 C3 FROM dual UNION ALL
16 SELECT 'ac' C1,'b.2' C2, 3 C3 FROM dual UNION ALL
17 SELECT 'ac' C1,'b' C2, 1 C3 FROM dual
18 )
19 SELECT
20 NVL2(LAG(C1) OVER (PARTITION BY C1,C2 ORDER BY C1,C2,C3),NULL,C1) C1
21 ,NVL2(LAG(C2) OVER (PARTITION BY C1,C2 ORDER BY C1,C2,C3),NULL,C2) C2
22 ,C3
23* FROM (SELECT DISTINCT c1,c2,c3 FROM sample_data)
SQL> /
C1 C2 C3
a b.1 1
2
3
a b.2 1
2
a b.3 1
ac b 1
ac b.1 1
2
ac b.2 1
2
C1 C2 C3
3
12 rows selected.
SQL>
Maybe you are looking for
-
ITunes will not open - the folder itunes cannot be found or created
I'm having troubles opening up itunes. Every time i click on the icon I get the following message The folder "iTunes" cannot be found or created, and is required. The default location for this folder is inside the My music folder. I had itunes on my
-
I have to design a java application that will be called PigLatin. An example of this would be if the user would enter the word dog the output of the program would be ogday. It takes the first letter of the word and moves it to the end of the word and
-
Range of values in a Between-condition?
Hello all, I need help for the following problem: I have records with a date-field with values from January 1999 till today. In a query I want to select all records where the date-field + 31 to +60 days are between the 1^st^ of January 2000 and the 3
-
I Hope Apple developers Will Read This !
I definitivly thing a found a REAL problem on the current ipod software... (I spent quite a large amount of time checking, so I hope it wont be useless...) I have (my iPod Has) problems reading files that have been encoded in AAC format using : - iTu
-
Re :VF11: reversal of debit memo not posting to accounting
Hi Friends, i am facing problem while cancelling debit memo through VF11. 1 st we had reated debitmemo request. then raised debit memo. then we tried to cancel debit memo. we are getting error saying account detrmination error. when i gave debit mem