query to find the number of dates
Hi all
I need assistance in creating a query. Ask the details I have given below.
Table:
Create the table emp_record (emp_id number, emp_join_date date);
insert into emp_record values (1, 1 June 14 ');
insert into emp_record values (2, 26 May 14 ');
insert into emp_record values (3, 16 May 14 ');
insert into emp_record values (4, 14 May 14 ');
Suppose I ran the query with sysdate, we need to subtract the date of sysdate, then a report should be prepared in function number how many have subtracted values sysdate below 0 to 3 days, 3-6 date.
Output should be like
0 - 3 3-6 6-9 days more than 9 days
1 0 1 2
Please help to write this query. Thank you
Hello
Do not essentially repeat the same CASE expression with the same types of calculations for each column. You can do the job with a CASE expression, like this:
WITH got_group_id AS
(
SELECT THE CHECK BOX
WHEN emp_join_date< trunc="" (sysdate)="" -="" 8 ="" then ="">
WHEN emp_join_date< trunc="" (sysdate)="" -="" 5 ="" then ="">
WHEN emp_join_date< trunc="" (sysdate)="" -="" 2 ="" then ="">
0 OTHERWISE
Group_id END AS
Of emp_record
WHERE emp_join_date<= sysdate ="" --="" if="">=>
)
SELECT *.
OF got_group_id
PIVOT (COUNT (*)
FOR group_id IN (0 '0-2 days'
, 3 AS a "3-5 days.
6 as a "6-8 days"
, 9 as "9 or more days.
)
)
;
It will be much easier to maintain when needs change.
ED mentioned, using a string, 1 June 14 ' in a place where we expect a date is just a matter of trouble. 2-digit years are too.
Tags: Database
Similar Questions
-
How to find the number of data items in a file written with the ArryToFile function?
I wrote a table of number in 2 groups of columns in a file using LabWindows/CVI ArrayToFile... Now, if I want to read the file with the FileToArray function so how do I know the number of items in the file. during the time of writing, I know how many elements array to write. But assume that I want the file to be read at a later time, then how to find the number of items in the file, so that I can read the exact number and present it. Thank you all
Hello
I start with the second question:
bytes_read = ReadLine (file_handle, line_buffer, maximum_bytes);
the second argument is the buffer to store the characters read, so it's an array of characters; It must be large enough to hold maximum_bytes the value NULL, if char [maximum_butes + 1]
So, obviously the number of lines in your text tiles can be determined in a loop:
Open the file
lines = 0;
While (ReadLine () > 0)
{
lines ++;
}
Close the file
-
Query to find the number of attached document
We've been checking out some of the attachments in the database and identified a number that are are very large, so we want to check what they are. How can I find the number of invoice/order/request for registration of the ebs if all I have is the info from fnd_documents & fnd_lobs.
You can collect the size of each by running this script:
Select fad.entity_name, sum (DBMS_LOB. GETLENGTH (FL.file_data)) SIZE_BYTES;
Count (*)
of fnd_documents fnd_lobs fl, fnd_documents_tl fdtl, fd, fnd_attached_documents ADF
where fd.media_id = fl.file_id
and fd.document_id = fdtl.document_id
and fd.document_id = fad.document_id
and fl.program_name is null
and fl.expiration_date is null
and fd.datatype_id = 6
and fdtl.language = 'en '.
and (fad.entity_name like '% po2'
OR fad.entity_name like '% REQ')
Fad.entity_name group;
You can find requisitions affected by the following:
SELECT THE PH. SEGMENT1, PH. PO_REQUISITION_LINES_ALL PL, PH PO_REQUISITION_HEADERS_ALL REQUISITION_HEADER_ID
WHERE PL. REQUISITION_HEADER_ID = PH. REQUISITION_HEADER_ID
AND PH. REQUISITION_HEADER_ID in)
SELECT PK1_VALUE FROM FND_ATTACHED_DOCUMENTS
WHERE ENTITY_NAME = 'REQ_HEADERS');
SELECT THE PH. SEGMENT1, PL. REQUISITION_LINE_ID
OF PO_REQUISITION_LINES_ALL PL,
PO_REQUISITION_HEADERS_ALL PH
WHERE PL. REQUISITION_HEADER_ID = PH. REQUISITION_HEADER_ID
AND PL. REQUISITION_LINE_ID in)SELECT PK1_VALUE FROM FND_ATTACHED_DOCUMENTS
WHERE ENTITY_NAME = 'REQ_LINES');
Please mark answers 'Proper' or 'Useful', as appropriate, to facilitate solutions to the other participants of the RTO.
If you do not see these buttons, open the chat in a new window/tab by right clicking on the object and choose "open in a new tab.
You should see Correct and helpful icons below each post.
-
query to find the number of contract coverage
Hi gurus,
I have a requirement to create a PO report that displays all the details in. with the hedge contract number. Please specify the query or advice on how to find this agreement number of coverage.
Nestorpo_headers_all. Segment1
-
SQL query to get the number of days monthwise
Hello
I'm new to sql, can someone please tell me query to find the number of days between the two dates months wise.
say
FIRSTDATE last date
21/03/2011-25/06/2011
March April May June
9 22 23 18Hello
Welcome to the forum!
Here's one way:
WITH all_dates AS ( SELECT start_date + LEVEL - 1 AS a_date FROM ( SELECT TO_DATE ('21/03/2011', 'DD/MM/YYYY') AS start_date , TO_DATE ('25/06/2011', 'DD/MM/YYYY') AS end_date FROM dual ) CONNECT BY LEVEL <= end_date + 1 - start_date ) SELECT TO_CHAR ( TRUNC (a_date, 'MONTH') , 'fmMonth YYYY' ) AS month , COUNT (*) AS num_days FROM all_dates WHERE a_date - TRUNC (a_date, 'IW') < 5 GROUP BY TRUNC (a_date, 'MONTH') ORDER BY TRUNC (a_date, 'MONTH') ;
What is a 'working day '? I guess you mean every day except Saturday or Sunday, but the query aboveare sometimes figures less than you have asked:
MONTH NUM_DAYS --------------- ---------- March 2011 9 April 2011 21 May 2011 22 June 2011 18
Are a few days working on Saturday or Sunday? How do you get the 22 working days in April 2011 and 23 in may?
SQL is good at obtaining results with a variable number of rows, but you have to say exactly the desired number of columns when you write the query.
If you really need the output of the way you said, with any number of columns, then watch in swing or a grouping of the chain . See the FAQ forum
https://forums.Oracle.com/forums/Ann.jspa?annID=1535
"4. How can I convert rows to columns. -
Find the number of days between the dates...
Hi friends,
I am new to this development of blackberry applications so I do not know how to find the number of days between two days. Y at - there any API is avilable otherwise we have to write our own code. In fact, I tried GregorianCalendar but I get error that cannot find the symbol but I already imported net.rim.device.api.util and package java.util also... Please give an idea how to solve this problem.
with respect,
s.Kumaran.
Use DateField class instances to represent dates on the screen.
And your code will be as follows:
long date1 = date1DateField.getDate ();
long date2 = date2DateField.getDate ();
-
Hello
SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate.
Please help on this script and let me know if you need more details.
---
You use a SELECT statement. Let me know if you need more details.
-
How can I find the number of users returned by cfldap query?
How can I find the number of users returned by cfldap query?
I'm not allowed to do something like:
< cfif ArrayLen (results.rows) WG 1 >
Then, I get an error:
faultCode:Server.Processing faultString:' unable to invoke CFC - class type object coldfusion.tagext.net.LdapResultTable can use table ' faultDetail: "
Thank you very much for all you can shed light
Expand on Dan's response.
#results. USNCreated # is a reference to the entire column. This shortcut is allowed inside of a
or a loop. But if you want to access the record set directly outside one of these structures of loop, you must use the query.column [full row] or ["column"] [rank] query syntax. THAT IS TO SAY
-
Hi all
Could someone knows how to find the number of users connected to the database without connection with sql * more
y at - it a command to find?
example, we have 10 databases in a server, how to find the number of users connected to the special data base without connecting to database(v$session)?
the Oracle version:-10g, 11g
Operating system:-OEL4, OEL5, AIX, Solaris
any help will be appreciated.
Thanks in advance.
Thank you.
Kind regards
Rajesh.but you can say total number of connection with the above given the command? It would also be useful to know.
See you soon,.
LKM -
Need help finding the number of occurrences of a model.
Hi all
I need help to find the number of occurrences of a model in the column of the table data.
Consider the examples of data - column of a row in a table:
'S-S-S-A-S-S-P-S-S-B-S-A-P-S-S-C '.
My requirement is:
I should get the County of S that are immediately preceded by or P.
for the above data, I should get are counted as 3 + 2 + 1 = 6 (S-S-S-A, S-S-P, S - A)
The configuration data is stored as type VARCHAR2.
Thanks in advance,
Girish G
Published by: Girish G on July 21, 2011 23:22I don't know that there is a better way, then this one:
SQL> with dt as 2 (select 'S-S-S-A-S-S-P-S-S-B-S-A-P-S-S-C' str from dual) 3 SELECT SUM(Regexp_count(Regexp_substr(str, '(S\-?)+(A|P)+', 1, 4 Regexp_count(str, '(S\-?)+(A|P)+') - ( 5 LEVEL - 1 )), 'S')) len 6 FROM dt 7 CONNECT BY LEVEL <= Regexp_count(str, '(S\-?)+(A|P)+') 8 / LEN ---------- 6
-
How to count the number of data records?
Hey guys, how to count the number of records, I had on a data object variable?
Im having a result of sql query in a variable like this:
oDB.resolveNode("#command").query.select.value = "SELECT * FROM Customers WHERE CliNombre LIKE ' % ' + input1 +" %' ";
oDB.open ();
oDB.first ();
So I need to count the number of records retrieved by this SQL query at the moment. Help please
Then move the cursor back to the first record after you have your account.
There is a keyword count in SQL that will allow you to get the account of your request. You can run that first - get your account, and then run the actual query to get the Recordset. This would require a separate data connection. Some examples of code.
var xfa.event.newText = inName;
If (inName == "") {}
App.Alert ("you must enter a name--try again!")
}
var nIndex = 0;
While (xfa.sourceSet.nodes.item (nIndex) .name! = "DataConnection2")
{
nIndex ++;
}oDB = xfa.sourceSet.nodes.item (nIndex) .racing var (1); pertaining to the specified data connection node
App.Alert (ODB.saveXML ("Pretty"));var nIndex = 0;
While (xfa.sourceSet.nodes.item (nIndex) .name! = "DataConnection3")
{
nIndex ++;
}
var oDBCount = xfa.sourceSet.nodes.item (nIndex) .racing (1); pertaining to the specified data connection node
Configure sql call DB to get the number of records that match the criteriaoDBCount.nodes.item (1).query.setAttribute ("text", "commandType");
oDBCount.nodes.item (1).query.select.nodes.item (0) .value = "Select count (*) from table1 where AcctNumber = '" + inName + "'";
oDBCount.open)
oDBCount.close)Configure sql call DB to get the specified employee number
oDB.nodes.item (1).query.setAttribute ("text", "commandType");
oDB.nodes.item (1).query.select.nodes.item (0) .value = "Select * from table1 where AcctNumber = '" + inName + "'";
App.Alert (ODB. Nodes.Item (1) .saveXML ("Pretty"));now connect to the DB and get a recording
oDB.open)
oDB.close ();Note the SQL command use the keyword count (take a look at the oDBCount section). This will return a number of return to the cllaer. When I set up the data connection, a node count (*) that appeared there. I dragged to the form and it has created a field called count that the onus at this node. When the query is executed, the number of resulting records returns to this field. You can have hidden it so that your users can not see it and also to change the binding votes to zero, so it is not included in the data file that is submitted when the form is complete.
Paul
-
to find the number of records retrieved in the select statement in the cursor
Hi all
with the cursor, I'm selecting select statement together and writing in the .txt file.
his worksheet, but it should not open the file, if the cursor returns nothing.
How to find the number of records returned by the select statement in the cursor.
pls help me.
Thank you...Don't understand what you're trying to say, but maybe it's...
DECLARE vCounter NUMBER; -- Other variables... BEGIN vCounter:=0; FOR .. IN cursor LOOP IF vCounter=0 THEN -- Here open file... -- Here write one time data... END IF; -- Here write cursor data... vCounter:=1; END LOOP; END;
-Clément
-
How to find the last update date, time and user of the file field peoplecode
How to find the last updated date time fields of peoplecode records?
Thank you.We can check the update date-time using the following query
SELECT LASTUPDDTTM IN THE PSPCMPROG WHERE OBJECTVALUE1 LIKE "RECNAME" AND OBJECTVALUE2 AS "FIELDNAME".
-
Query to retrieve the number of transactions in every 1 hour for the end
Hello
Could someone help to write a query to retrieve the number of transactions in every hour for the last month.
Case:
I / P
If Timestamp1
1 01/01/2008 00:00:01
CAS2 01/01/2008 00:01:01
case3 01/01/2008 01:00:01
1 01/01/2008 01:02:01
case4 01/01/2008 01:10:01
Service5 01/02/2008 02:00:01
Case6 01/02/2008 02:10:01
case7 2008-02-01 23:00:01
.............................
.............................
case... 2008-01-31 00:24:00
O/P
cases of to_time of time
2008-01-01 00:00:00 01/01/2008 01:00 2
2008-01-01 01:00:01 01/01/2008 02:00 3
.........................
.........................
etc.
Any help really appreciatedWe can do this by using analytic functions
Here's what I did:
create table timestamp1 (date of ts)
Select * from timestamp1
2008-10-30 15:41:13
2008-10-30 15:41:05
2008-10-30 15:40:03
2008-10-30 14:58:26
2008-10-30 14:29:45
2008-10-30 13:17:48
2008-10-30 08:29:50
2008-10-30 06:05:51
2008-10-30 03:41:52
2008-10-30 02:29:54Select distinct to_char (ts, 'hh24') frmhrs,
TO_CHAR (ts, 'hh24') + 1 tohrs, count (ts) OVER (order by to_number (to_char (ts, 'hh24')) RANK BEFORE (1/24))
of timestamp1
When trunc (ts) = trunc (sysdate) - I added this just to make sure that I get for data of today
order of frmhrsFRMHRS TOHRS CNT
1-3-02
03-4-1
06 7 1
1-9-08
13 14 1
14 15 2
15 16 3You can customizeas by your need.
-
How can I find the number of pixels is in my photos of the ipad? I sell on ebay and they have new requirements for the photos. 500 pixels on the longest side. Is it possible to increase the pixels on already took pictures?
See if this application works for you > https://itunes.apple.com/us/app/image-size/id670766542?mt=8
Maybe you are looking for
-
Disappread name of the left in iMessage column shows only photo
The column on the left in iMessage on my mac is only showing pictures and the display is no longer names. How can I change the display to show again the names as photo?
-
How to change the display of the list of recent jobs on lenovo vibe turned?
Hi, I looked everywhere in the settings to find the way to change the display of list of recent jobs... I used to use the stacked styles, and out of nowhere, there is a menu to change the styles, now it displays the app recently opened next door... I
-
Can I upgrade Mac Book Pro 2010 Hard Drive 500 GB 750 GB or 1 TB
-
Question about my account hotmail and re - install windows xp
I have to take my computer repair. They will have to remove my windows xp home addition and reinstall it. Will my windows live hotmail content and all the emails always be there when I connect
-
Installation DRIVERS error code noon says that I must first uninstall all other unused midi drivers
Original title: MIDI DRIVERS try to install a yamaha usb driver... error code says that I need to first uninstall unused midi... pilots knew there were others, I searched but not found... Please help