Timestamp in minutes on case condition
Hi Gurus,
I wanted to find the diff between two timestamp in minutes on case condition
when type=1 then min(col2) and type=2 then max(col2)
type-(datatype-numeric)
col2-(datatype-timestamp)
how can i do this
Thanks
Hi,
Sorry, the question could means diozens of different things.
This is the answer to one of them:
SELECT id
, ... -- other columns from individual rows
, MAX ( CASE
WHEN type = 2
THEN col2
END
) OVER (PARTITION BY id)
- MIN ( CASE
WHEN type = 1
THEN col2
END
) OVER (PARTITION BY id) AS dif
FROM table_x
;The dif column will be an INTERVAL DAY TO SECOND., which you can convert to a number if you need to.
Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data. Explain how you get those results from that data.
Always say what version of Oracle you are using.
Similar Messages
-
Diff between two timestamp in minutes on case condition
Hi Gurus,
I wanted to find the diff between two timestamp in minutes on case condition
when type=1 then min(col2) and type=2 then max(col2)
type-(datatype-numeric)
col2-(datatype-timestamp)
how can i do this
ThanksHi,
Is this a question about the Berkeley DB SQL product?
If so, you should look at the documentation on time fields in the SQLite page here:
http://www.sqlite.org/datatype3.html#datetime
Otherwise, you are asking this on the wrong forum.
Regards,
Alex Gorrod
Oracle Berkeley DB. -
Diff in two timestamp in minutes
Hi Gurus,
I wanted to find the diff between two timestamp in minutes on case condition
when type=1 then min(col2) and type=2 then max(col2)
type-(datatype-numeric)
col2-(datatype-timestamp)
how can i do this
ThanksIm guessing you want like bleow
time-----------------type--------------------diff
10/11/2010-------1-----------------------10/23/2010minus10/12/2010
10/23/2010--------1---------------------10/23/2010minus10/12/2010
10/12/2010---------2---------------------10/23/2010minus10/12/2010
10/04/2010---------2----------------------10/23/2010minus10/12/2010
is it correct? -
Hi,
this is some diff question from same logic,
i wanted to use timestamp format in case condition
case when start
date > '2019-08-08 00:00:00' then TIMESTAMPDIFF(SQLTSI_MINUTE,"Esr"."Power Off",TIMESTAMP '2011-08-22 00:00:00' )
getting error message
Oracle Error code: 1843, message: ORA-01843: not a valid month at OCI call
Pleasehelp
thanksI think the real issue here is that you are dealing with 2 different datatype in one column...
You have start_date which is date, but your timestampdiff fucntion will give you result in number. So the bottomline is that you can't have 2 different data type in one field..
I'd leave start_date column as it is and create another field called timediff and use timestampdiff expression in that column. So column timediff column will give you results in number for all of the start dates..
Then based on the result of timediff column, for example, if you can spot that for everything that the start date > 2019-08-08 00:00:00, the timediff value is > 300 (just an example). Then you can apply filter or even a case statement there to pick everything greater than 300..
Let me know if it makes sense -
How to assign the parameter in case condition?
Dear All,
I have one procedure say p1. I want to pass one parameter like d_forcd = 'IN' and ALC_Code in ('11', '21', '31') from this procedure.
In begin part I have one query. Can I pass this paramer in case condition in that query.
If possible please hint me.
Thanks in advance,
Prathamesh.
[pre]There is probably a way using CASE, but it seems easier without:
SQL> var param varchar2(10)
SQL>
SQL> exec :param := 'IN'
PL/SQL procedure successfully completed.
PARAM
IN
SQL> SELECT * FROM dual
2 WHERE ( :param = 'IN' AND dummy IN ('A','B','X','Y')
3 OR NVL(:param,'?') != 'IN' );
D
X
1 row selected.Substitute your actual PL/SQL parameter for the SQL*Plus variable. -
Case condition in where clause
Hi
I'm a SQL beginner but according to my reading of the manual, this syntax should be acceptable. I'm using it in application express but tested it also in SQL developer and finding that it fails with an "invalid relational operator" error, with the line number pointing to the ELSE clause of the CASE condition, but a column number pointing to white space.
This is a nested select but that shouldn't matter. The fragment in question is this:
select some columns
from res
where res.villaid = :P605_VILLAID
and INSTR(:P604_RES_STATES, res.states) != 0
and (CASE :P604_EXCLUDE_ZERO
WHEN 'Y' THEN 'res.rate > 0'
ELSE 'res.rate >= 0'
END)
and res.DEPARTDATE > :P605_STARTDATE
and res.ARRIVEDATE <= :P605_ENDDATE,
I hope this formats ok when posted. The code is looking for reservations in a date range (which works fine when the other conditions are commented out), and should only output zero-rate rows (complimentary nights) if the user asks for this in the P604_EXCLUDE_ZERO bind variable. There are probably other ways to go about this, but I am too stubborn to give up on this. Well, not yet anyway.
Thanks and regards
CSselect some columns
from res
where res.villaid = :p605_villaid
and instr (:p604_res_states, res.states) != 0
and sign (res.rate) >= case when :p604_exclude_zero = 'Y' then 1 else 0 end
and res.departdate > :p605_startdate
and res.arrivedate <= :p605_enddate -
I am trying to create a calculation based on the following case condition. For some reason its working fine on a existing report but now when I am creating a new report based on this, its giving error "Invalid Combinations of Condition and Calculations" any thoughts?
I have also found out that when I am adding "ELSE" in the condition then only it's throwing that error otherwise working fine. I have also tried to recreate this case condition in my select statement and tested in TOAD and it runs without a problem.
CASE WHEN ( Reference Date < TO_DATE(:Date) ) AND ( Support Start Date > TO_DATE(:Date) ) THEN TO_DATE(:Date) ELSE Reference Date ENDTry to wrap the "AND" and re-select the items into
the case since it looks like the " are missing.
CASE WHEN ( "Reference Date" < TO_DATE(:Date) AND
"Support Start Date" > TO_DATE(:Date) ) THEN
TO_DATE(:Date) ELSE "Reference Date" ENDTried that too but no luck :(. As I said before the same condition is working fine in another existing similar report. I am working on some changes in the existing report and when I am putting this condition it just throws this error message.
Message was edited by:
DiscoverDiscoverer -
Hi,
i wanted to add a case condition in which it sshould change the colour of the row else none. it possible in obiee
thanksHi,
Create a new column in your report with your case statement : CASE condition then 1 else 0 End (and hide it)
Go to your column for which you want to change the color of the row the go to the properties and specify a conditional formatting based on your condition.
If 1 then apply color elso nothing.
Regards
Adil -
Requests per minute in idle conditions in EM
Hello Gurus,
We are having an issue where in our Financial Reporting server is going down after throwing an Out of memory error in the logs in Weblogic.
We have been monitoring the Financial Reporting service in the Weblogic console and in the Enterprise Manager to see the performance and have observed the following --
- Initially the Heap free percent in the Financial Reporting server is staying at 70 - 80 percent for some time immediately after the services are started.
- The heap free percent keeps on going down as the time proceeds.
- The heap goes to 0 and ultimately the services goes into shutdown state in weblogic and becomes unaccesible.
We also observed that the Financial Reporting service shows requests per minute to 80 in the env where we are facing this issue, however it is showing as 0 in the other env which are exact replica - http://s15.postimg.org/bt756hvuj/NEW_PROD_FR_in_Enterprise_Manager_Idle_Condition.png
If someone can point us on what we need to check that would be great. as we are not sure as to why the request per minute will be around 80 in idle conditions.
Any help will be highly appreciated.
Thanks,
hyperionEPMSid_Middleware wrote:
Hmmm... you can always try to boot up weblogic with more memory. Look at $DOMAIN_HOME/bin/setDomainEnv.cmd (or .sh in unix) and check for MEM_ARGS variable which specifies memory settings. Double the memory requirements and restart weblogic and see what happens.Increasing the memory is not a concern here, but the thing is that it keeps on going down even when our servers are idle.
Also, what is Requests (per minute) as shown in the screenshot and do you know why the Requests (per minute) is showing around 80 even when there is no work going on?
We have other environment which are again idle and the value is 0 there.
Thanks,
hyperionEPM -
To remove error from error message screen stnd SAP in case condition met
Hi all,
I have a strange problem may be not to you guys,
well i am showing an error message in ME21N on certain condition in EXIT 'EXIT_SAPMM06E_012' this is working fine i am using simple stmt Message e(MSGno) text-01, but when i correct the problematic part and again want to save my data it is aloowing me to save data but my error message(In red) still remains there if i see in EDIT ( of faulty messages pop-up window). Can any body know if we have to remove error message manually in case our program satify the condition.
if yes what portion i m missing to delete the error message.
any reply will be highy appreciated <REMOVED BY MODERATOR>
Mandy
Edited by: Alvaro Tejada Galindo on Feb 7, 2008 10:51 AMWell we can remove message from message text tray using pre-defined macros to erase message.its like
IF SY-SUBRC NE 0.
IF NOT tekpo-id IS INITIAL.
"This is to remove error message later on
"if problem corrected.
mmpur_business_obj_id tekpo-id.
ENDIF.
mmpur_metafield mmmfd_item_userexit.
mmpur_message 'E' 'ZMM02' '050'
'Intraplant STO :' '' '' ''.
else.
"To erase message
mmpur_metafield mmmfd_item_userexit .
mmpur_remove_messages_by_id tekpo-id.
ENDIF.
its working for one line item, if more then one line item you need to verify it.
ENJOY SAP -
CASE Condition Causing Plan Difference
Version
SQL> SELECT * FROM v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
5 rows selected.
Optimizer
SQL> show parameter optimizer
NAME TYPE VALUE
_optimizer_autostats_job boolean FALSE
_optimizer_join_elimination_enabled boolean FALSE
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.2.0.2
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean FALSE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
Problem
We have a vendor system that constructs the SQL to be sent to the database. These queries have the following generic structure for a WHERE clause condition:
CASE WHEN <condition> THEN <table>.<column> END = '<value>'We've noticed significantly different execution plans when the optimizer compares numbers instead of varchar2. The examples below demonstrate that. In our case this difference is impacting the execution plans of a larger query effectively doubling buffer gets and resulting in execution times that are 2-4 times as worse.
Query 1
SQL> SELECT /*+gather_plan_statistics*/ * FROM DUAL WHERE CASE WHEN 1=1 THEN 'X' END = dummy;
D
X
1 row selected.
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(null,null,'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID 6ghjubgpwpr61, child number 0
SELECT /*+gather_plan_statistics*/ * FROM DUAL WHERE CASE WHEN 1=1 THEN
'X' END = dummy
Plan hash value: 272002086
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
| 0 | SELECT STATEMENT | | 1 | | 1 |00:00:00.02 | 2 | 2 |
|* 1 | TABLE ACCESS FULL| DUAL | 1 | 1 | 1 |00:00:00.02 | 2 | 2 |
Predicate Information (identified by operation id):
1 - filter("DUMMY"='X')
Query 2
SQL> SELECT /*+gather_plan_statistics*/ * FROM DUAL WHERE CASE WHEN 'A'='A' THEN 'X' END = dummy;
D
X
1 row selected.
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(null,null,'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID gcpwzksqr2w9n, child number 0
SELECT /*+gather_plan_statistics*/ * FROM DUAL WHERE CASE WHEN 'A'='A'
THEN 'X' END = dummy
Plan hash value: 272002086
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 0 | SELECT STATEMENT | | 1 | | 1 |00:00:00.01 | 2 |
|* 1 | TABLE ACCESS FULL| DUAL | 1 | 1 | 1 |00:00:00.01 | 2 |
Predicate Information (identified by operation id):
1 - filter("DUMMY"=CASE WHEN ('A'='A') THEN 'X' END )In my eyes the condition 'A' = 'A' is equivalent to the condition 1=1. How come in the case of the numeric comparison Oracle can eliminate the case expression but in the character comparison it cannot?
Thanks!Centinul wrote:
In my eyes the condition 'A' = 'A' is equivalent to the condition 1=1. Well, issue is Oracle looks at 'A' = 'A' as string comparison. And string comparison result is NLS setting dependent. That's why it can't evaluate CASE at compile time.
SY. -
Please help to build an sql from the given expression to build case condition with Where clause
if @rollno is not null then
Select top 1 studentid from student where rollno =:@rollno
else
if @regno is not null then
Select top 1 studentid from student where regno =:@regno
Please help me to create the above condition as a single sql statement . I will pass two argument in to the sql.
With Thanks
Pol
polachanSelect top 1 studentid from student
where (rollno =:@rollno or :@rollno is null)
and (regno =:@regno or :@regno is null)
The above expression will work in SQL server
I'm not sure you're using sql server as syntax like :@regno are not t-sql valid
so you can try the above and if it doesnt work please try in the relevant forums for more help in case you're using a different RDBMS
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Convert difference in timestamps to minutes
Hello, using Oracle 11g R2.
Looking for a way to convert the differnce in systimestamps to number of minutes.
select systimestamp - order_received_ts
from order_table
where order_id = 17978Etbin wrote:
select (systimestamp - (systimestamp-2)) * 24 * 60 from dual
+3300 00:20:29.525280
select (systimestamp - (systimestamp-2)) * 24 * 60 from dual
(SYSTIMESTAMP-(SYSTIMESTAMP-2))*24*60
+000002880 00:04:20.318880000
just look at the days
Regards
Etbin
select (3300-2880)/60 h from dual
H
7
Learned something: the second term systimestamp-2 looses the time zone but the first term systimestamp has it and it is taken into account. So if you're in India it's just the "expected behaviour"
Message was edited by: Etbin something I haven't thought of
I will take sometime to understand your statement there about "second systimestamp -2 loosing timezone" and the query has been executed from Singapore though
Cheers,
Manik. -
How to avoid Huge scan with case condition in the select statement.
Hi ,
I have the below sql and add condition such that c.ROLE = 18 then tibex_fixrestorestateview needs to be queried else it should not query the tibex_fixrestorestateview.
tibex_fixrestorestateview contains 10 to 20 millions records so to avoid scanning when c.ROLE <> 18
SELECT c.connectionid, u.participantid, c.port, u.PASSWORD, cg.gatewayid,
c.ROLE, u.cancelonlogout, NVL (f.tofixsequence, 1) AS tofix,
NVL (f.fromfixsequence, 1) AS fromfix
FROM tibex_connectiongroup cg INNER JOIN tibex_connection c
ON cg.connectiongroupid = c.connectiongroupid
LEFT JOIN tibex_user u ON c.connectionid = u.userid
*LEFT JOIN tibex_fixrestorestateview f*
ON u.useralias = f.useralias AND c.ROLE = 18;Regards
NMHi;
I suggest close your issue here as answered than move your issue Forum Home » Database » SQL and PL/SQL which you can get more quick response
Regard
Helios -
Case condition is not giving the correct result in Union query
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(FeeDate,Clerk,ClrComm,ExComm,TagComm) as select
20120102,'Mathews',25,56,245 from dual union all select
20120102,'Lika',0,56,245 from dual union all select
20120102,'Ram',0,0,245 from dual union all select
20120102,'Angilo',NULL,NULL,245 from dual union all select
20120102,'Nikki',225,NULL,245 from dual union all select
20120103,'Ram',NULL,556,2345 from dual union all select
20120103,'Lika',NULL,NULL,245 from dual union all select
20120103,'Mathews',25,56,245 from dual;DML Used -
SELECT FEEDATE,CLERK,SUM(ClrComm) ClrComm,null ExComm,null TagComm,sum(case when ClrComm>0 then ClrComm end) Comm
from tt2
group by FEEDATE,CLERK
UNION
SELECT FEEDATE,CLERK,null ClrComm,sum(ExComm) ExComm,null TagComm,sum(case when ExComm>0 then ExComm end) Comm
from tt2
group by FEEDATE,CLERK
UNION
SELECT FEEDATE,CLERK,null ClrComm,null ExComm,sum(TagComm) TagComm,sum(case when ClrComm=0 or ClrComm is NULL and ExComm=0 or ExComm is NULL then TagComm end) Comm
from tt2
group by FEEDATE,CLERKResult Output -
FEEDATE CLERK CLRCOMM EXCOMM TAGCOMM COMM
20120102 Angilo 245 245
20120102 Angilo
20120102 Lika 0
20120102 Lika 56 56
20120102 Lika 245 245
20120102 Mathews 25 25
20120102 Mathews 56 56
20120102 Mathews 245
20120102 Ram 225 225
20120102 Ram 0
20120102 Ram 490 490
FEEDATE CLERK CLRCOMM EXCOMM TAGCOMM COMM
20120103 Lika 245 245
20120103 Lika
20120103 Mathews 25 25
20120103 Mathews 56 56
20120103 Mathews 245
20120103 Ram 556 556
20120103 Ram 2345
20120103 Ram
Output expected -
FEEDATE CLERK CLRCOMM EXCOMM TAGCOMM Comm
20120102 Mathews 25 56 245 81
20120102 Lika 0 56 245 56
20120102 Ram 0 0 245 245
20120102 Angilo 245 245
20120102 Nikki 225 245 225
20120103 Ram 556 2345 556
20120103 Lika 245 245
20120103 Mathews 25 56 245 81I sincerely thanks to all of you for your effort in advance.This way:
select feedate, clerk, clrcomm, excomm, tagcomm,
sum(decode(nvl(clrcomm, 0) + nvl(excomm, 0), 0, tagcomm, nvl(clrcomm, 0) + nvl(excomm, 0))) over (partition by feedate, clerk) comm
from tt2
order by feedate, clerk;
FEEDATE CLERK CLRCOMM EXCOMM TAGCOMM COMM
20120102 Angilo 245 245
20120102 Lika 0 56 245 56
20120102 Mathews 25 56 245 81
20120102 Nikki 225 245 225
20120102 Ram 0 0 245 245
20120103 Lika 245 245
20120103 Mathews 25 56 245 81
20120103 Ram 556 2345 556
8 rows selected
Maybe you are looking for
-
How do I transfer my iTunes account to a new computer?
I'm trying to use Home Sharing to transfer my iTunes account from one computer to another. Home Sharing is turned "on" on both computers, but I cannot find any way to import my account on the new computer. How is this done? Thanks!!
-
Hi. I'm living in an old office building with a lot of other people. We have a cable modem in the basement which feeds ethernet to a router upstairs, and that router feeds two others. At any given moment the system might have as many as 8-10 users. V
-
Fast Motion of Video Clip and Playing in opposite direction
Has anyone figured out how to speed up the motion of a clip yet or has figured out to reverse the play of a clip on this new version. It is unclear like previous versions how to do this.
-
Service Level Report values not matching to Service Level Dashboard v 2.0 values
Hi Experts, We have installed SLD v2 on a development SQL server along with WSS 3.0. The SLD is pointed to the SCOM datawarehouseDB to collect the information to have it up in the dials. We have SCOM 2007 R2 who's OpsMgrDB and OpsMgrDWDB are hosted o
-
Hi, I work with ID sc5.5, and I'm trying to add a hyperlink to a file. The objective is a pdf presentation that would include links to mp4 clips. I've created a shape in the inDesign document and used the "window>interactive>Hyperlink" to link it to