Thread: [cx-oracle-users] calculate time differences on timestamp column
Brought to you by:
atuining
From: <prz...@po...> - 2011-07-06 12:22:25
|
Hello, I have a table with one timestamp column: ----------------------------------------- -------- ---------------------------- ID NOT NULL NUMBER(10) DOC NOT NULL NUMBER(10) TIME NOT NULL TIMESTAMP(6) TYPE_OF_OPER NOT NULL VARCHAR2(1) SIZE NUMBER(10) DESC VARCHAR2(200) When I select from this table (just two columns) TIME TYPE_OF_OPER --------------------------------------------------------------------------- - 11/07/06 13:03:45,826773 D 11/07/06 13:03:45,848394 E 11/07/06 13:03:46,978210 F 11/07/06 13:07:48,053144 A 11/07/06 13:07:48,072237 B 11/07/06 13:07:48,444520 C 11/07/06 13:07:48,504301 D 11/07/06 13:07:48,532285 E 11/07/06 13:07:49,504860 F 11/07/06 13:07:50,554859 A ... (over 10000 rows) Our developer records timestamps in important part of his application: code A ... record timestampt 'A' code B ... record timestampt 'B' code C ... record timestampt 'C' code D ... (there are only 'A'-'F' timestamps). What I'd like to achive is to get delta time between 'A' and 'B' (= time of code 'B') but for all 'A' and 'B' (as an output I get rows of numbers). How can I calculate this using cx-oracle ? Regards Przemyslaw Bak (przemol) ---------------------------------------------------------------- Znajdz samochod idealny dla siebie! Szukaj >> http://linkint.pl/f29e2 |
From: Gerrat R. <gri...@co...> - 2011-07-06 12:48:53
|
> -----Original Message----- > From: prz...@po... [mailto:prz...@po...] > Sent: July 6, 2011 8:22 AM > To: cx-...@li... > Subject: [cx-oracle-users] calculate time differences on timestamp > column [snip] > What I'd like to achive is to get delta time between 'A' and 'B' (= > time of code 'B') > but for all 'A' and 'B' (as an output I get rows of numbers). > How can I calculate this using cx-oracle ? > > > Regards > Przemyslaw Bak (przemol) Your question is a straight SQL question, and has nothing to do with cx_Oracle. There is a great website, www.stackoverflow.com that this question is perfect for. You might get better results if you asked it there. ...your question might have even been asked & answered there already: http://stackoverflow.com/questions/4308620/difference-in-time-between-re cords |
From: <prz...@po...> - 2011-07-06 13:12:07
|
On Wed, Jul 06, 2011 at 08:38:24AM -0400, Gerrat Rickert wrote: > > -----Original Message----- > > From: prz...@po... [mailto:prz...@po...] > > Sent: July 6, 2011 8:22 AM > > To: cx-...@li... > > Subject: [cx-oracle-users] calculate time differences on timestamp > > column > > [snip] > > > What I'd like to achive is to get delta time between 'A' and 'B' (= > > time of code 'B') > > but for all 'A' and 'B' (as an output I get rows of numbers). > > How can I calculate this using cx-oracle ? > > > > > > Regards > > Przemyslaw Bak (przemol) > > Your question is a straight SQL question, and has nothing to do with > cx_Oracle. > There is a great website, www.stackoverflow.com that this question is > perfect > for. You might get better results if you asked it there. > > ...your question might have even been asked & answered there already: > http://stackoverflow.com/questions/4308620/difference-in-time-between-re > cords I thought that to get the result I need to have two cursors going through the data and substract between them. Indeed - my SQL knowledge it very small ... ;-) Regards Przemyslaw Bak (przemol) ---------------------------------------------------------- Kredyt gotowkowy nr 1! Teraz do 150 000zl bez zaswiadczen! http://linkint.pl/f29e1 |
From: Anthony T. <ant...@gm...> - 2011-07-06 13:49:20
|
Hi, You can simply subtract them. cx_Oracle will return a datetime instance for the timestamp column and you can simply do timestampB - timestampA which will return to you a timedelta instance. You can also subtract them in Oracle and return the result to Python if you prefer that option. Anthony On Wed, Jul 6, 2011 at 6:22 AM, <prz...@po...> wrote: > Hello, > > I have a table with one timestamp column: > ----------------------------------------- -------- ---------------------------- > ID NOT NULL NUMBER(10) > DOC NOT NULL NUMBER(10) > TIME NOT NULL TIMESTAMP(6) > TYPE_OF_OPER NOT NULL VARCHAR2(1) > SIZE NUMBER(10) > DESC VARCHAR2(200) > > When I select from this table (just two columns) > TIME TYPE_OF_OPER > --------------------------------------------------------------------------- - > 11/07/06 13:03:45,826773 D > 11/07/06 13:03:45,848394 E > 11/07/06 13:03:46,978210 F > 11/07/06 13:07:48,053144 A > 11/07/06 13:07:48,072237 B > 11/07/06 13:07:48,444520 C > 11/07/06 13:07:48,504301 D > 11/07/06 13:07:48,532285 E > 11/07/06 13:07:49,504860 F > 11/07/06 13:07:50,554859 A > ... (over 10000 rows) > > Our developer records timestamps in important part of his application: > > code A ... > record timestampt 'A' > code B ... > record timestampt 'B' > code C ... > record timestampt 'C' > code D ... > (there are only 'A'-'F' timestamps). > > What I'd like to achive is to get delta time between 'A' and 'B' (= time of code 'B') > but for all 'A' and 'B' (as an output I get rows of numbers). > How can I calculate this using cx-oracle ? > > > Regards > Przemyslaw Bak (przemol) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ---------------------------------------------------------------- > Znajdz samochod idealny dla siebie! > Szukaj >> http://linkint.pl/f29e2 > > ------------------------------------------------------------------------------ > All of the data generated in your IT infrastructure is seriously valuable. > Why? It contains a definitive record of application performance, security > threats, fraudulent activity, and more. Splunk takes this data and makes > sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-d2d-c2 > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |
From: Walter D. <wa...@li...> - 2011-07-07 09:26:05
|
On 06.07.11 15:49, Anthony Tuininga wrote: > Hi, > > You can simply subtract them. cx_Oracle will return a datetime > instance for the timestamp column and you can simply do > > timestampB - timestampA > > which will return to you a timedelta instance. You can also subtract > them in Oracle and return the result to Python if you prefer that > option. Or you could use the LAG() or LEAD() analytic functions. Servus, Walter |