How can I get a number of consecutive records?
I've broken down my problem to a simpler car usage issue. (My table has very many more lines, the types of car and car names.)A car is used in the order, but not every day. Each row of the table represents a sequential use.
I want to know the number of times wherever it has been used in the order and then the first day and the last day of this use.
I think I need to use MORE than PARTITION, but I don't know how.
If anyone can provide a solution or point me in the right direction for the reply I really appreciate it!
Here are the data in the table:
TRANSACTION_NO CAR_TYPE CAR_NAME TRANSACTION_DATE
2 CUP D 28/02/2012 03:36:37
3 CUP D 28/02/2012 03:38:37
12 CUP D 29/02/2012 10:04:58
CUT 183 D 26/03/2012 12:18:41
CUT 184 D 26/03/2012 13:56:43
CUT 185 F-26/03 / 2012 15:24:44
CUP 186 F-26/03 / 2012 18:02:55
CUT 206 F 03/04 / 2012 00:13:48
207 CUT E 03/04/2012 05:39:29
208 CUT E 03/04/2012 08:32:02
E CUP 272 09/04/2012 11:21:26
E CUP 273 14:34:26 09/04/2012
274 CUT D 09/04/2012 17:42:25
D 275 CUT 09/04/2012 21:29:32
D 276 CUT 10/04/2012 00:31:57
349 CUT D 15/04/2012 16:41:16
CUT 350 F 15/04 / 2012 18:21:54
CUTTING 351 F 15/04 / 2012 20:10:12
CUT 376 F 19/04 / 2012 01:57:39
CUT 377 F 19/04 / 2012 05:43:06
CUT 380 F 19/04 / 2012 08:26:25
CUT 381 F-19/04 / 2012 12:19:27
This is the result I want (car note D and F have been reused twice):
CAR TimesUsed First_use_date Last_use_date
5 D 28-02-2012 03:36:37 03/26/2012 13:56:43
F 3 03/26/2012 15:24:44 04/03/2012 00:13:48
E 4 04/03/2012 05:39:29 04/09/2012 14:34:26
4 D 04/09/2012 17:42:25 04/09/2012 14:34:26
F 6 04/15/2012 18:21:54 04/19/2012 12:19:27
Here is the table and data.
CREATE TABLE CAR_USE
(
TRANSACTION_NO NUMBER (3).
CAR_TYPE VARCHAR2 (10 BYTE),
CAR_NAME VARCHAR2 (2 BYTE),
DATE OF TRANSACTION_DATE
)
LOGGING
MONITORING;
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(2, 'CUT', HAS ', TO_DATE (FEBRUARY 28, 2012 03:36:37 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(3, 'CUT', HAS ', TO_DATE (FEBRUARY 28, 2012 03:38:37 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(12, 'CUT', HAS ', TO_DATE (FEBRUARY 29, 2012 10:04:58 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(183, 'CUT', HAS ', TO_DATE (MARCH 26, 2012 12:18:41 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(184, 'CUT', HAS ', TO_DATE (MARCH 26, 2012 13:56:43 ',' ' DD/MM/YYYY HH24:MI:SS));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(185, 'CUT', 'F', TO_DATE (MARCH 26, 2012 15:24:44 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(186, 'CUT', 'F', TO_DATE (MARCH 26, 2012 18:02:55 "," MM/DD/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(206, 'CUT', 'F', TO_DATE (APRIL 3, 2012 00:13:48 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(207, 'CUT', 'E', TO_DATE (APRIL 3, 2012 05:39:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(208, 'CUT', 'E', TO_DATE (APRIL 3, 2012 08:32:02 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(272, 'CUT', 'E', TO_DATE (APRIL 9, 2012 11:21:26 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(273, 'CUT', 'E', TO_DATE (9 APRIL 2012 14:34:26 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(274, 'CUT', HAS ', TO_DATE (9 APRIL 2012 17:42:25 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(275, 'CUT', HAS ', TO_DATE (9 APRIL 2012 21:29:32 ',' ' DD/MM/YYYY HH24:MI:SS));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(276, 'CUT', HAS ', TO_DATE (APRIL 10, 2012 00:31:57 ',' ' DD/MM/YYYY HH24:MI:SS));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(349, 'CUT', HAS ', TO_DATE (APRIL 15, 2012 16:41:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(350, 'CUT', 'F', TO_DATE (APRIL 15, 2012 18:21:54 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(351, 'CUT', 'F', TO_DATE (APRIL 15, 2012 20:10:12 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(376, 'CUT', 'F', TO_DATE (19 APRIL 2012 01:57:39 "," MM/DD/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(377, 'CUT', 'F', TO_DATE (APRIL 19, 2012 05:43:06 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(380, 'CUT', 'F', TO_DATE (19 APRIL 2012 08:26:25 "," MM/DD/YYYY HH24:MI:SS'));))
Insert into CAR_USE
(TRANSACTION_NO, CAR_TYPE, CAR_NAME, TRANSACTION_DATE)
Values
(381, 'CUT', 'F', TO_DATE (APRIL 19, 2012 12:19:27 ',' DD/MM/YYYY HH24:MI:SS'));))
COMMIT;
Hello
Welcome to the forum!
Using the technique of Difference sets , you can do it with 1 single subquery:
WITH got_grp_id AS
(
SELECT car_name, transaction_date
, ROW_NUMBER () OVER ( ORDER BY transaction_date)
- ROW_NUMBER () OVER ( PARTITION BY car_name
ORDER BY transaction_date
) AS grp_id
FROM car_use
)
SELECT car_name
, COUNT (*) AS times_used
, MIN (transaction_date) AS first_use
, MAX (transaction_date) AS last_use
FROM got_grp_id
GROUP BY car_name
, grp_id
ORDER BY first_use
;
For an explanation and more examples of fixed difference technique, see
{message: id = 9953384}
{message: id = 9957164}
Thanks for posting the CREATE TABLE and INSERT statements; It's very helpfuul!
Published by: Frank Kulash, 18 may 2012 16:41
Tags: Database
Similar Questions
-
How can I get a number of words for a PDF doc or a selected passage?
How can I get a number of words for a PDF doc or a selected passage?
Select text, copy in Word, use the properties of this word.
-
I don't have serial number to activate the software acrobat X 1 pro. How can I get the number?
Hey johnt92241602,
I have checked with your account and could see that you have purchased an annual subscription for one year.
There is no need for a serial number to activate Acrobat subscription.
After you install Acrobat XI pro, all you need is to log in to adobe.com with your Adobe ID and password to activate the software.
Kind regards
Ana Maria
-
How can I get a number of records?
I have a dataprovider that points to the results of a query on a SQL database. That is directed to a grid of data. How can I get the number of records in the dataprovider or data grid?
You can try like this,
new XMLList (dataProvider) .length)
-
Hello!
I bought my edition student of Adobe CS Design Premium 5.5 in December 2011 and recently reinstalled my laptop forget out before serial number. I still have the invoice with this purchase "Unimall GmbH" (which does not have its business more and thus couldn t help me) and the box of the product with the code produced on this subject. It s is not possible for me to follow the normal procedure, because I m not a student anymore and, therefore, can´t download a registration certificate.
How can I get my serial number now?
Thanks in advance for your help and best regards
Andrea
contact your school and check your account, Adobe ID Code
-
How can I get the number to redeem?
Hello!!! I bought Adobe Photoshop elements 13 in a store, but I have a MAc Pro so I Don t have CD lector. How can I download it? I found the serial number, but I need the number to buy, how can I get it? Thank you
Hi monican.
You can download PSE 13 from this link. Products download Photoshop Elements | 10, 11, 12, 13
In addition, a redemption code is used to acquire your serial No. Redeem your code for your serial number. Instructions here: Redemption Code help
See you soon!
~ David
-
How can I get the number of rows in the table using Sunopsis API target in ODI 10 g?
Hi guys,.
In fact, I want to send an alert message as soon as the interface is run from a package. I've included alert OdiSendMail that sends an email once the interface is running.
Could someone please tell how to get the number of rows inserted into the table the Sunopsis API target.
I tried to use < % = odiRef.getNbRows () % >, but this has not worked for me. Since I am a beginner, could you please help out me
This is my mail to send ODI format
"The population of data managed to < % = odiRef.getSysDate () % >
Total of lines in the target table is: < - need an API code-> "
Kind regards
Clinton
Published by: LawrenceClinton on February 25, 2013 20:53Hello
Create the project with details below variable
Nom_de_variable: Total_Row_Count
Type of variable: Variable discount
Definition tab:
Data type: digital
Action: No persistentRefresh the tab:
Schema: provide the schema of your repository to work and beSELECT log.nb_row
THE journal of snp_step_log, snp_scen_step step
WHERE log.nno = step.nno
AND step.scen_no = (SELECT scen_no FROM snp_scen_step WHERE step_name='<%=odiRef.getPrevStepLog ('STEP_NAME") % > ')
AND log.sess_no = '< % = odiRef.getSession ("SESS_NO") % >' code at low
AND step.step_name = ' < % = odiRef.getPrevStepLog ("STEP_NAME") % > 'Note: add this variable after the stage of interface in your package (after the interface anywhere you can place), you can add this variable before ODISendEmailNotification in your package
call this varciable * #Total_Row_Count * in the Notification of ODISendEmail
for example :
Data has been fulfilled successfully in < % = odiRef.getSysDate () % >
Total no of lines filled are: * #Total_Row_Count *it will work
cordially,
Phanikanthedited by: Phanikanth on February 28, 2013 01:13
edited by: Phanikanth on February 28, 2013 01:14
-
my mother-in-law is trying to reinstall windows xp home edition 2, but does not have its product number or key... How can I find out who it is?
Thank you very much!
What brand is the PC? Most system builders put the key on the side of the Machine. If it's a laptop, it should be on the bottom of the laptop.
It is all the information that we will be able to give you. If you are unable to find the key, then you will need to purchase a new license.
Serving the community a computer at once [link to paid support not allowed in this forum] Please post a reply to let us know whether or not our response helped.
-
I use to have a count of the total number of mails in my Inbox. This was listed next to "inbox" in my list of folders. With the latest version, it is gone and I can't find anything in the settings which may bring back this feature. I see the number of emails by right clicking on the folder, but I would love to just see it again a glance.
You have this add-on?
https://addons.Mozilla.org/en-us/Thunderbird/addon/extra-folder-columns/
http://chrisramsden.vfast.co.UK/3_How_to_install_Add-ons_in_Thunderbird.html
-
I try to get the caller ID (telephone number or the call history) at the time of the incoming call. TrueCaller has implemented it and they get the phone number of the caller and the call also history.
Please help me get there.
Tips:
1 CoreTelephony Framework(It gives only calling states)
2 apples 9.0 update: "Maybe" contacts sync. with the mail application and detects the incoming phone number.
3 TrueCaller App https://www.truecaller.com/articles/iphone
https://iTunes.Apple.com/app/truecaller-enhances-your-phonebook/id448142450
You're talking not here who you think you are. Please read the terms of the user agreement you signed.
-
How can I get the number of Excel in Teststand in the Office Toolkit?
We are in the process of transition of 8 LabVIEW and TestStand 3.5 to 2009 LabVIEW and TestStand 4.2. We use Microsoft Office Toolkit a little in our work to manipulate Excel and have problems with it. For example, if I try to use the new Report.vi to open an Excel file, it will open the file successfully, but the 'report' that we would normally have the reference number for the workbook is grayed out with an unknown type. VI of the sample and the screenshot attached. All the ideas that we have put in place bad?
Thank you...
parkerfly,
Between 8,0 LabVIEW and LabVIEW 2009 (I think that the change was with the version of LabVIEW 8.5), the report generation tool has been updated to use the LabVIEW Classes. This means that the report on the outputs output parameter a LabVIEW class, which can be used by another generation of report live to refresh the report. Unfortunately, LabVIEW classes are not currently supported in TestStand. The only solution is to create wrapper screws that take the exit and flatten it into a string so it can be stored in TestStand. Then, for any VI that he would use, you would need a wrapper VI to take the string entry and convert into a class of LabVIEW (nireport.lvclass) so it can be used in the generation of reports other screws more information in this regard lie in this post on the forum: http://forums.ni.com/ni/board/message?board.id=330&message.id=14786&requireLogin=False . The forum post is a few years ago, but the information is still valid.
-
How can I get the number of display automatically on a table line?
I have an array of measures, and I would like the line number to display on each line. The challenge is that everytime I run the program, the total number of lines will be different, so I'd figures updated every time that I run the program based on the current number of lines.
I've attached a picture to illustrate what I'm doing.
Find the attached example (registered in the 2009 version), and you can extract what you need for your code!
-
I can't find my PIN code. How can I get this number?
My husband needs his PIN to reset his hotmail. He also needs another personal question because he can't remember his response.
Hello
I'm sorry, but we cannot help with hotmail problems in these forums in response to vista
Please repost your question in hotmail in the hotmail link below forums
http://windowslivehelp.com/product.aspx?ProductID=1
ForumsConsult with Microsoft Certified Solutions -
How can I get the number of the line causing the error?
If I try to catch an error with try-catch...
The object of e which is containing the text error message is not to store the line number where the error occurred.
try { error; } catch ( e ) { $.writeln( e.toSource() ) ; }
We are in a html extension Panel, not in extendscript toolkit.
The result is: (new ReferenceError ("syntax is not defined"))
It would be extremely useful that we could get the line number.
Thank you!
the following doesn't work for you?
try { error; } catch ( e ) { $.writeln( e.toSource() ); $.writeln( e.line ); }
Concerning
-
How can I get the number of disks for a virtual machine and PAHO are / s of a disc?
Hi all
I would like to know if there is a command that returns the number of disks having a virtual machine.
and also if there is no command to obtain and change the number of the IOPS / disk s.
Thanks in advance
Carlos
It will give you hard drives attached
Get - VM | Hard drive
It will give you count
Get - vm | Select name, @{N = "TotalHDD"; E={($_ | (Get-harddisk).count}}
It is possible to retrieve the number of the IOPS / disk s, but what do you mean by editing.
Maybe you are looking for
-
No sound during the game NFS Rivals
I have a HP Envy 15 J049TX.While playing NFS Rivals I don't get everything in the sounds of the game. The strange thing is that I hear for other applications I have on my system. I tried unistalling the game and install it again, updated my directx a
-
Series HP Zook: DST short Test failed
Unable to start my computer this morning, I ran hardware diagnostics. The computer memory checking and SMART in vain check the DST short. Error code: UFH3HF-000840-XD7V7F-60SL03Product ID: G8B26UC #ABA I know that usually a DST failed test means that
-
I need DRM for windows media player XP
I can't install the movie on my computer
-
How can I get my application code?
How can I get my application code?I have Deskjet 1050 All - in - One J410a... please me guild!
-
Failed to create empty document
When I try to open any management or the Device Manager I have an error mmc window that says: "cannot create document empty."If anyone knows the cause and the fix for this problem?