Group by with date range.
Hello
I'm looking for an efficient use of the group however the date range.
I have a table of transaction as below.
Date customer_no amount_paid
---------------------------------------------------------------
1st December 13 001 500
2 December 13 001 360
9 December 13 001 200
2 November 13 001 360
9 November 13 001 200
2 November 13 001 360
9 October 13 001 200
2 October 13 001 360
9 October 13 001 200
02 sep-13 001 360
200 001 13 - Sep - 09
............... etc.
I would like to see sum (amount_paid) by past varies from 1 to 30 days 31-60 days, 61 to 90 days.
Here are the results expected.
Amount_paid duration of customer
--------------------------------------------------------------
001 1 - 30 980
001-60 450 31
001 1200 61 - 90
002 1 - 30 300
002 31-60 490
002 61-90 320
003 1 - 30 450
......................etc.
I group by customer only the date range (1-30, 31-60, 61 - 90.etc).
Can someone make me a request for it.
Thank you...
Hedde.
Select customer_no,
case
When trunc (sysdate) - trunc (dt)< 31="" then="">
When trunc (sysdate) - trunc (dt)< 61="" then="">
another 61-90 '
the end time,
Sum (amount_paid) amount_paid
from your_table
where dt between sysdate - dt between 0 and 90
Customer_no group,
case
When trunc (sysdate) - trunc (dt)< 31="" then="">
When trunc (sysdate) - trunc (dt)< 61="" then="">
another 61-90 '
end
/
SY.
Tags: Database
Similar Questions
-
Windows Backup & restore leaves gaps in the backup period date ranges
I noticed that backup & restore leaves gaps in the date ranges displayed on the screen of backup periods under the function to manage the space. This means that files change during the interval periods have not been saved? For example, the screen shows currently backups and the following periods:
Jan 26: 12-18 Mar, 12 GB 10.40
Apr 04, 12-13 Apr, 12 GB 19.62
27 April, 12-27 Apr, 12 GB 05.16
May 06,12 - May 06,12 02.41 GB
May 27.12 - 17 Jun, 12 GB 03.41
What is the importance of gaps?
How can I tell that B & R is fully backup all files that changed since the last backup run?
How can I varify the 1st backup is a backup full?
How can I varify that the system image backup is up-to-date?
I save approximately once a week to a USB external hard drive. I use options "Include a system image" and "Let me choose" to select the files and have selected the option 'keep only the last frame system & minimize the space used '.
Hello
Backups are created in sets called backup periods. To maximize your disk space, Windows backup backup all folders selected, the first time it's run and then it only backs up files that are new or have been modified since the last backup was made. Periodically, Windows creates a new, full backup. Each full backup is called in a backup. When you view your backups of files, you can see all the backup periods with date ranges. If you decide to delete backups of files, you should always keep the most recent backup of the file.
Reference:
Should what backup settings I use to maximize my disk space? http://Windows.Microsoft.com/en-us/Windows7/what-backup-settings-should-I-use-to-maximize-my-disk-space
Back up and restore: frequently asked questions
http://Windows.Microsoft.com/en-us/Windows7/products/features/backup-and-restore
-
AMOUNT of Oracle with the date range
Hello community,
I'm having a problem with the addition of a field with a date range. It comes to my table
JVREF VARCHAR2 10 - - - - - - SOURCE VARCHAR2 2 - - - - - - PERIOD VARCHAR2 6 - - - - - - JVDATE NUMBER - 38 0 - Nullable - - GLCODE VARCHAR2 24 - - - - - - DESCR VARCHAR2 40 - - - Nullable - - AMOUNT_0 FLOAT 48 48 - - Nullable - - AMOUNT_1 FLOAT 48 48 - - Nullable - - JVTYPE VARCHAR2 4 and I'm glad the the following statement works as expected
SELECT AMOUNT_1 FROM 'TABLE' where
TO_DATE ("PERIOD, ' YYYYMM") > = to_date ("'201501 ',' YYYYMM")
and
TO_DATE (PERIOD, 'YYYYMM') < = to_date ("'201502 ',' YYYYMM");
E.g.
AMOUNT_1
56192.48
59863.57
48570.1
72407.12
21626.96
35532.96
75860.67
25623.62
54799.83
16872.3
The next thing I want to do is the sum of these amounts... so I changed my statement to become
SELECT SUM (AMOUNT_1) 'TABLE' where
TO_DATE ("PERIOD, ' YYYYMM") > = to_date ("'201501 ',' YYYYMM")
and
TO_DATE (PERIOD, 'YYYYMM') < = to_date ("'201502 ',' YYYYMM");
and now I'm getting
ORA-01841: (full) year must be between-4713 and 9999 and not 0
I also tried
SELECT THE PERIOD (AMOUNT_1) SUM OF "BRE". "' OPW_NMLTRX ' where
TO_DATE ("PERIOD, ' YYYYMM") > = to_date ("'201501 ',' YYYYMM")
and
TO_DATE (PERIOD, 'YYYYMM') < = to_date ("'201502 ',' YYYYMM")
Group by PERIOD
with the same results... I can't figure out what I should do next?
Thank you.
Hello
Solomon Yakobson says:
Question:
SELECT *.
From your_table
WHERE the TO_NUMBER (SUBSTR (PERIOD, 1, 4)) NO BETWEEN-4713 and 9999
OR TO_NUMBER (SUBSTR (PERIOD, 1, 4)) = 0
/
To find the offending rows.
SY.
This can cause other errors, according to what is in this column. A better way would be something like:
Primary_key SELECT, period - add more columns you want
'TABLE' - avoid names which need quotation marks
(Period WHERE the TRANSLATION)
'012345678'
'999999999'
) <> = "999999"
OR SUBSTR (period, 1, 4), not BETWEEN "1900" AND "2099"
OR SUBSTR (period 5) NOT BETWEEN '01' to '12'
;
Now there may be errors of conversion, because there is no conversion.
-
GROUP BY date range to identify duplicates revisited!
Good afternoon
It is a continuation of the previous discussion, I previously created GROUP BY date range to identify duplicates
Your help with the following would be appreciated (examples of data below)
I've highlighted what I mark as returned to double as below:
Definition of duplicate (However, this is slightly different to the previous post)
the same account_num
maximum 20 days apart tran_effective_date
tran_processed_date maximum 10 days apart
the same tran_amount
However, I do not want to return a duplicate if they have both a tran_priced_date filled.
So, in light of the foregoing, I don't expect the following account_numbers to be marked as duplicate:
N100283 - one of the records has populated trab_priced_date
N101640 - none of the records have the tran_priced_date filled
N102395 - same as N101640
N102827 - same as N101640
N108876 - although the two documents have the populated tran_priced_date, the tran_effective_dates are more than 20 days apart.
BUT for the rest of the accounts, N100284 and N102396 I want to execute the following logic
Compare the 3rd rank in 4th place and ask the following questions:
Is tran_effective_date to a maximum of 20 days out?
Is tran_processed_date maximum 10 days apart?
If yes then report it as dupe
Compare line 4 to 5, then ask the same question until you get to the line 4 or 5. When everything is done, I want to examine only the transactions that have the status of normal and if the above question is true for both and then return to my game of result as dupes.
I hope that makes sense!
BEGIN EXECUTE IMMEDIATE 'DROP TABLE samp_data'; EXCEPTION WHEN OTHERS THEN IF SQLCODE = -942 THEN DBMS_OUTPUT.put_line(''); ELSE RAISE; END IF; END; / CREATE TABLE samp_data ( ACCOUNT_NUM VARCHAR2(17), TRAN_ID NUMBER(10), TRAN_TYPE VARCHAR2(50), TRAN_EFFECTIVE_DATE TIMESTAMP(6), TRAN_PROCESSED_DATE TIMESTAMP(6), TRAN_STATUS VARCHAR2(17), TRAN_PRICED_DATE TIMESTAMP(6), TRAN_AMOUNT NUMBER(13,2) ); / Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N100283',140119178,'Regular With',to_timestamp('01-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 07.00.34.235000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('21-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),200); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE,TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N100283',140158525,'Regular With',to_timestamp('13-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('26-MAY-15 08.39.14.090000000 AM','DD-MON-RR HH.MI.SS.FF AM'),'Normal', null,200); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N100284',140118826,'Regular With',to_timestamp('03-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 07.00.19.072000000 AM','DD-MON-RR HH.MI.SS.FF AM'),'Normal', to_timestamp('20-MAY-15 03.25.05.438000000 AM','DD-MON-RR HH.MI.SS.FF AM'),450); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N100284',140158120,'Regular With',to_timestamp('06-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('23-MAY-15 08.38.42.064000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Reversed', to_timestamp('21-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),450); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N100284',140158120,'Regular With',to_timestamp('06-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('02-JUN-15 08.38.42.064000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('31-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),450); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N101640',140118957,'Regular With',to_timestamp('18-MAY-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 07.00.25.015000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', null,120); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N101640',140158278,'Regular With',to_timestamp('22-MAY-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('26-MAY-15 08.38.56.228000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', null,130); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N102395',140118842,'Regular With',to_timestamp('03-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 07.00.19.665000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', null,250); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N102395',140158235,'Regular With',to_timestamp('03-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('26-MAY-15 08.38.53.093000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', null,250); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N102396',140118823,'Regular With',to_timestamp('09-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('18-MAY-15 07.00.18.931000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('19-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),750); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N102396',140158099,'Regular With',to_timestamp('16-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('24-MAY-15 08.38.39.443000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Reversed', to_timestamp('21-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),750); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N102396',140158099,'Regular With',to_timestamp('16-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('29-MAY-15 08.38.39.443000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('30-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),750); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N102396',140158099,'Regular With',to_timestamp('12-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 08.38.39.443000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Reversed', to_timestamp('30-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),750); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N102396',140158099,'Regular With',to_timestamp('14-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('23-MAY-15 08.38.39.443000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Reversed', to_timestamp('30-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),750); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N102827',140118850,'Regular With',to_timestamp('03-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 07.00.20.045000000 AM','DD-MON-RR HH.MI.SS.FF AM') , 'Normal',null,157.84); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N102827',140158118,'Regular With',to_timestamp('03-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('26-MAY-15 08.38.41.861000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', null,157.84); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N108876',139840720,'Regular With',to_timestamp('01-MAY-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('11-MAY-15 08.35.34.646000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('20-MAY-15 03.25.05.438000000 AM','DD-MON-RR HH.MI.SS.FF AM'),1000); Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) values ('N108876',139889880,'Regular With',to_timestamp('22-MAY-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('12-MAY-15 08.49.29.080000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('21-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),1000); / select * from samp_data ORDER BY account_num, tran_effective_date, tran_processed_date;
PL continue the discussion in your original post
-
SQL to count the number of days of January with a range of dates
I have data like this, how to calculate the number of days with January in this date range.
BEGINNING END DAYS OF JAN 12/12/2013 20/01/2014 20 21/01/2014 02/02/2014 11 Hello
So, you want to count the number of days between
(a) either start_dt, or January 1, 2014 (prevailing later) and
(b) or end_dt or January 31, 2014 (whichever comes first).
However, if start_dt and end_dt are prior to January 2014 (or both are later) which will result in a number negative if you take the difference or 0, if it is higher.
This looks like a job for the GREATER and LESS than functions.
SELECT start_dt - START is not a column name good
, end_dt - is neither END
BIGGER (1 + LESS (end_dt, DATE ' 2014-01-31'))
-Most GREAT (start_dt, DATE '' 2014-01-01)
* v
) AS jan_days
FROM table_x
;
If you would care to post CREATE TABLE and INSERT instructions for some examples of data, then I could test it.
-
Copy files from specific date ranges in a Batch file
I'm trying to copy files from a folder with many subfolders to another drive using a batch file. I want to copy the files in the date ranges specific (e.g. 01/01/2016 to 03/31/2016).
I use this with Xcopy command:
xcopy "C:\Users\John\Pictures\*.*" F:\BACKUP\Pictures/s/h/i/y
It works, but I want to send groups of files by date for the different destination folders. I'm having a problem by specifying a date range in the command line.
Is this possible with xcopy or robocopy? Does anyone know how to list the date rang in the command?
Thankss in advance,
John
Hello
Please contact Microsoft Community.
I understand you wanted to know about the files and folders by using the copy command line.
I suggest you go through the links below:
Refer to the suggestion given by SpiritX MS MVP replied on 14 August 2010 and check if that helps:
If the still the problem persists, I suggest you to post your query on TechNet:
Feel free to write us again with the status of the issue.
-
To ignore the date ranges that overlap
Hi guys,.
I have the tables below
Periods
START_DATE END_DATE ID 30-SEP-05 13 OCTOBER 05 1 12 OCTOBER 05 14 NOVEMBER 05 2 15 NOVEMBER 05 15 DECEMBER 05 3 T1
DAT_COL ID AMOUNT 11 OCTOBER 05 1 10 12 OCTOBER 05 1 10 16 NOVEMBER 05 1 10 I need to ignore the remaining date range if it overlaps when comparing dat_col from T1 between the dates of beginning and end of periods table. Always need to consider the first periods
output something like this
ID ID_1 START_DATE END_DATE DAT_COL 1 1 30-SEP-05 13 OCTOBER 05 11 OCTOBER 05 1 1 30-SEP-05 13 OCTOBER 05 12 OCTOBER 05 1 3 15 NOVEMBER 05 15 DECEMBER 05 16 NOVEMBER 05 I use query
Select a.id, b.id, b.start_date, b.end_Date, a.DAT_COL from T1 a, (select id, start_date, end_date periods) b
where a.dat_col between b.start_Date and b.end_Date
Group of a.id, b.id, b.start_date, b.end_Date, a.dat_col
order of b.start_date;
ID ID_1 START_DATE END_DATE DAT_COL 1 1 30-SEP-05 13 OCTOBER 05 11 OCTOBER 05 1 1 30-SEP-05 13 OCTOBER 05 12 OCTOBER 05 1 2 12 OCTOBER 05 14 NOVEMBER 05 12 OCTOBER 05 1 3 15 NOVEMBER 05 15 DECEMBER 05 16 NOVEMBER 05 Test case:
CREATE TABLE 'PERIODS '.
("START_DATE" DATE,
"END_DATE" DATE,
'ID '.
) ;
Insert into periods (start_date, end_date, ID) values (to_date('30-SEP-05','DD-MON-RR'),to_date('13-OCT-05','DD-MON-RR'),1);
Insert into periods (start_date, end_date, ID) values (to_date('12-OCT-05','DD-MON-RR'),to_date('14-NOV-05','DD-MON-RR'),2);
Insert into periods (start_date, end_date, ID) values (to_date('15-NOV-05','DD-MON-RR'),to_date('15-DEC-05','DD-MON-RR'),3);
Insert into T1 (DAT_COL, ID) values (to_date('11-OCT-05','DD-MON-RR'), 1);
Insert into T1 (DAT_COL, ID) values (to_date('12-OCT-05','DD-MON-RR'), 1);
Insert into T1 (DAT_COL, ID) values (to_date('16-NOV-05','DD-MON-RR'), 1);
CREATE TABLE 'T1 '.
(DATE OF THE 'DAT_COL',
'ID '.
);
Hello
If you really want to use something close to what you posted, then you can do it like this:
WITH got_r_num AS
(
SELECT a.id
b.id AS id_1
b.start_date
b.end_date
a.dat_col
, ROW_NUMBER () OVER (PARTITION BY a.id, a.dat_col)
ORDER BY b.start_date, b.end_date
) AS r_num
FROM one t1
, (
SELECT id, start_date, end_date
Periods
) b
WHERE a.dat_col BETWEEN b.start_date
AND b.end_date
GROUP BY a.id, b.end_date, a.dat_col, b.start_date and b.id
)
SELECT id, id_1, start_date, end_date, dat_col
OF got_r_num
WHERE r_num = 1
ORDER BY start_date
;
Note that the WITH clause, that's essentially what you posted in your first post (with the added r_num column) and the main request is essentially the same as in response #1.
But why would you do something like that? View online or GROUP BY allows all. If you remove them, you get the #1 response solution.
-
Hi Experts,
A very happy new year to all of you (a little in advance)!
I have a table where I have the id of employee and the task assigned with the start dates and end dates. Overlap in the dates of the tasks is a data delivers however I know how to spot them and eliminate. There is therefore no date of tasks that overlap
Employee_id
Task_No
Task_Start_date
Task_End_Date
Examples of data
1 T1 1 January 2014 February 28, 2014
1 T2 March 1, 2014 31 December 2014
2 T1 23 January 2014 31 December 2014
2 T2 1 January 2015 December 31, 2073 (means end of time)
3 T3 1 January 2014 July 15, 2014
3 T4 August 1, 2014 31 December 2014
T5 4 1 January 2014 December 31, 2073
I want to design a query where I provide the end date and it will list all the employees that are free for the same day from 1 January 2014. Thus, for example, if I give December 31, 2014, it will list the
EmpId (first day where the employee is free)
2 January 1, 2014
3 July 16, 2014
If I give the end = end date of time(31-Dec-2013), result-
EmpId (first day where the employee is free)
1 January 1, 2015
2 January 1, 2014
3 July 16, 2014
If I give the end = date January 31, 2014, expected - result
EmpId (first day where the employee is free)
1 January 1, 2015
I conceived after the request, but he intercepted not 2 employee ID. Also, it provides no flexibility to change end date-
Select *.
from (select employe_id,
task_start_date,
task_end_date,
lag (task_end_date, 1, task_start_date) on prev_end_date (partition by employee_id arrested by task_start_date)
of shop.employee_tasks
where task_end_date > = trunc (sysdate))
where task_start_date - prev_end_date > 1
Thanks in advance!
Kind regards
This is an example of what I call the query 'free time': you have the dates when you are busy and you want the dates where you are free.
You can find a nice solution for the problem of base here: ask Tom "SQL Query to find gaps in the date ranges" (search for solution of Anthony Boucher). Please note that this solution works even with the date ranges overlap.
To apply the solution here, first create the test data (please do it yourself in the following questions).
create table t(Employee_id, task_no, Task_Start_date, task_end_date) as select 1, 'T1', to_date('01-jan-2014'), to_date('28-feb-2014') from dual union all select 1, 'T2', to_date('01-Mar-2014'), to_date('31-Dec-2014') from dual union all select 2, 'T1', to_date('23-jan-2014'), to_date('31-dec-2014') from dual union all select 2, 'T2', to_date('01-jan-2015'), to_date('31-dec-2073') from dual union all select 3, 'T3', to_date('01-jan-2014'), to_date('15-jul-2014') from dual union all select 3, 'T4', to_date('01-aug-2014'), to_date('31-dec-2014') from dual union all select 4, 'T5', to_date('01-Jan-2014'), to_date('31-Dec-2073') from dual;
In the query, you must add records for yesterday and for the "end date" you want. This allows you to "free time" before and after the date ranges in your table.
Now, you partition by order of Task_Start_date and employe_id. Using the analytical function of the max (task_end_date), you get the last date of end so far. Add 1 and you get the first time (maybe). To make sure that the date is free, it must be before the next start date.
variable end_date varchar2(64) exec :end_date := '31-Dec-2073'; -- with boundaries as ( select trunc(sysdate)-1 task_start_date, trunc(sysdate)-1 task_end_date from dual union all select to_date(:end_date)+1, to_date(:end_date)+1 from dual ), data as ( select * from t where task_end_date >= trunc(sysdate) and task_start_date < :end_date union all select distinct a.employee_id, null, b.task_start_date, b.task_end_date from t a, boundaries b ) select employee_id, min(free_start) free_start from ( select employee_id, max(task_end_date) over (partition by employee_id order by task_start_date)+1 free_start, lead(task_start_date) over (partition by employee_id order by task_start_date)-1 free_end from data ) where free_start <= free_end group by employee_id;
EMPLOYEE_ID FREE_START 1 JANUARY 1, 15 2 1 JANUARY 14 3 16 JULY 14 -
Receive every month between date Range
Hi all
I said you want to display the month and year for the date range. IE Start date: 01-11-12, end Date: 31/05/13
SELECT COUNT(T1.CUST_NM) AS COUNT, TO_CHAR(T1.CREATE_DT,'MON-YY') AS MONTH, SUM(T3.DISBURSEMENT_LIMIT) AS TOTAL FROM CUSTOMER T1, ACCOUNT T2, LOAN_ACCOUNT T3, CREDIT_APPL T4, PORTFOLIO T5 WHERE T1.CUST_ID = T2.CUST_ID AND T2.ACCT_ID = T3.ACCT_ID AND T3.APPL_ID = T4.APPL_ID AND T4.PORTFOLIO_ID = T5.PORTFOLIO_ID and t1.CREATE_DT between to_date('01-01-10','DD-MM-YY') and to_date('30-12-10','DD-MM-YY') GROUP BY TO_CHAR(T1.CREATE_DT,'MON-YY')
Exit SQL:
County Month-year Total 8 JAN-10 15300 6 FEB-10 4245000 11 AUG-10 144500 6 DEC-10 15500 Now SQL returns matching records to date. But the requirement is to display the name of the month, the number and total 0 if there is no data found.
Power required:
County Month-year Total 8 Jan 15300 1 Feb-10 118750 0 March-10 0 0 Apr-10 0 0 May - 10 0 0 Jun - 10 0 0 Jul-10 0 11 Aug-10 144500 0 Seven.-10 0 0 Oct-10 0 0 Nov - 10 0 6 Dec - 10 15500 Please suggest me SQL to archive the above of the requirement.
Thanks and greetings
Saami
Try this
with t
as
(
Select count (t1.cust_nm) as County
to_char(t1.create_dt,'mon-yy') per month
, sum (t3.disbursement_limit) total
the t1 client
in t2
loan_account t3
credit_appl t4
the t5 portfolio
where t1.cust_id = t2.cust_id
and t2.acct_id = t3.acct_id
and t3.appl_id = t4.appl_id
and t4.portfolio_id = t5.portfolio_id
and t1.create_dt between to_date ('01-01-10', ' dd-mm-yy')
and to_date ('30-12-10', ' dd-mm-yy')
Group
by to_char(t1.create_dt,'mon-yy')
)
t1
as
(
Select to_char (add_months (to_date('01-01-10','dd-mm-yy'), level-1), 'Mon - yy') month_list
of the double
connect
by add_months (to_date('01-01-10','dd-mm-yy'), level-1)<= >= >
)
Select nvl (t.count, 0) as County
t1.month_list per month
, nvl (t.total, 0), as total
from t1
left
Join t
on t1. month_list = t.month
-
Hi all
This is our requirement.
We must combine records with time.
for example: period = 3
TABLE: XX_SALES
---------------------------------------------
XDATE XQTY
---------------------------------------------
10 5/1/2012
20 2/5/2012
3/5/2012 30
4/5/2012 60
12 2012/5/7
8/5/2012 23
45 8/5/2012
100 12/5 / 2012
5/2012/13 55
5/2012/15 99
== >
---------------------------------------------
XDATE XQTY
---------------------------------------------
1/5/2012 10-> 5/1/2012 Group (5/1/2012 ~ 3/5/2012)
2/5/2012 20-> 5/1/2012 Group (5/1/2012 ~ 3/5/2012)
3/5/2012 30-> 5/1/2012 Group (5/1/2012 ~ 3/5/2012)
4/5/2012 60-> Group 5/2012/4 (4/5/2012 ~ 2012/5/6) *.
7/5/2012 12-> Group 5/2012/7 (5/7/2012 ~ 9/5/2012) *.
8/5/2012 23-> Group 5/2012/7 (5/7/2012 ~ 9/5/2012) *.
8/5/2012 45-> Group 5/2012/7 (5/7/2012 ~ 9/5/2012) *.
5/2012/12 100-> Group 5/12/2012 (2012/5/12 ~ 14/5/2012) *.
13/5/2012 55-> Group 5/12/2012 (2012/5/12 ~ 14/5/2012) *.
5/15/2012 99-> Group 5/15/2012 (15/5/2012 ~ 5/17/2012) *.
After amount to combine with period = 3, the result will be
---------------------------------------------
XDATE_G XQTY_G
---------------------------------------------
60 1/5/2012
4/5/2012 60
2012/5/7 80
12/5/2012 155
5/2012/15 99
Here's the example script
We can solve this problem by using the loop now:create table XX_SALES(XDATE DATE, XQTY Number); insert into XX_SALES VALUES(to_date('20120501','YYYYMMDD'),10); insert into XX_SALES VALUES(to_date('20120502','YYYYMMDD'),20); insert into XX_SALES VALUES(to_date('20120503','YYYYMMDD'),30); insert into XX_SALES VALUES(to_date('20120504','YYYYMMDD'),60); insert into XX_SALES VALUES(to_date('20120507','YYYYMMDD'),12); insert into XX_SALES VALUES(to_date('20120508','YYYYMMDD'),23); insert into XX_SALES VALUES(to_date('20120508','YYYYMMDD'),45); insert into XX_SALES VALUES(to_date('20120512','YYYYMMDD'),100); insert into XX_SALES VALUES(to_date('20120513','YYYYMMDD'),55); insert into XX_SALES VALUES(to_date('20120515','YYYYMMDD'),99);
to find the XDATE_G and it's rank in the loop and the XQTY in the range of the sum.
Is it possible to solve this problem by using analyze sql?DECLARE V_DATE_FROM DATE := NULL; V_DATE_TO DATE := NULL; V_QTY_SUM NUMBER := 0; CURSOR CUR_DATE IS SELECT DISTINCT XDATE FROM XX_SALES ORDER BY XDATE; BEGIN FOR REC IN CUR_DATE LOOP IF V_DATE_TO IS NULL OR REC.XDATE > V_DATE_TO THEN V_DATE_FROM := REC.XDATE; V_DATE_TO := REC.XDATE + 3 - 1; SELECT SUM(XQTY) INTO V_QTY_SUM FROM XX_SALES WHERE XDATE >= V_DATE_FROM AND XDATE <= V_DATE_TO; DBMS_OUTPUT.PUT_LINE(TO_CHAR(V_DATE_FROM, 'YYYYMMDD') || '-----qty: ' || TO_CHAR(V_QTY_SUM)); END IF; END LOOP; END;
Thanks in advance,
Best regards
Zhxiang
Published by: zhxiangxie on April 26, 2012 14:41 fixed the grouping expected dataThere was an article about a similar problem in Oracle Magazine recently:
http://www.Oracle.com/technetwork/issue-archive/2012/12-Mar/o22asktom-1518271.html
See the section on the 'grouping beaches '. They needed a total cumulative who started once the total reaches a certain amount.
You need a total cumulative which starts again when the date changes to group and the dates of beginning and end of each group must be determined dynamically.
This can be done with the analytical functions.
Here is a solution-based 'code listing 5', the solution MODEL, which is recommended in the article.
SELECT FIRST_DATE, SUM(XQTY) SUM_XQTY FROM ( SELECT * FROM xx_sales MODEL DIMENSION BY(ROW_NUMBER() OVER(ORDER BY XDATE) RN) MEASURES(XDATE, XDATE FIRST_DATE, XQTY) RULES( FIRST_DATE[RN > 1] = CASE WHEN XDATE[CV()] - FIRST_DATE[CV() - 1] >= 3 THEN xdate[cv()] ELSE FIRST_DATE[CV() - 1] END ) ) GROUP BY first_date ORDER BY first_date; FIRST_DATE SUM_XQTY --------------------- -------- 2012/05/01 00:00:00 60 2012/05/04 00:00:00 60 2012/05/07 00:00:00 80 2012/05/12 00:00:00 155 2012/05/15 00:00:00 99
If you 9i, there is no function model. In this case, I can give you a solution using START WITH / CONNECT BY that does not work as well.
-
summarize records by date range
I have an ambitious project where I need to report a summary report for a date range for each code. I'm not against the use of a helper function plsql to calculate the summary result because I'm not sure it can be done in sql. Any help would be appreciated as my attempts have failed.
Here is a sample of the data.
ID START_DATE END_DATE
445 1 January 2010 Thursday, April 30, 2010 - simultaneous example
445 1 JANUARY 2010 MAY 31, 2010
445 17 MAY 2010 AUGUST 6, 2010
2710 1 May 2010 August 31, 2010 - row example
2710 01 - SEP - 2010 DECEMBER 31, 2010
2710 1 JANUARY 2011 APRIL 30, 2011
2710 1 MAY 2011 AUGUST 31, 2011
658 1 January 2010 Thursday, April 30, 2010 - simultaneous example
658 1 JANUARY 2010 MAY 31, 2010
658 1 JANUARY 2010 MAY 31, 2010
108 28 December 2009 January 22, 2010 - non-consecutive example
108, 29 MARCH 2010 APRIL 11, 2010
108. ON MAY 1, 2010 MAY 31, 2010
2535 1 March 2010 March 14, 2010 - example 2 consecutive and non-consecutive 1 combination
2535, MARCH 15, 2010 MARCH 28, 2010
2535, APRIL 5, 2010 MAY 2, 2010
999 1 March 2010 March 14, 2010 - example 2 simultaneous and consecutive 1 combination
999, 1 MARCH 2010 APRIL 24, 2010
999 APRIL 25, 2010 MAY 2, 2010
Here is the result summary of what I would be returned as for each ID
ID START_DATE END_DATE
445 1 JANUARY 2010 AUGUST 6, 2010
2710 1 MAY 2010 31 AUGUST 2011
658 1 JANUARY 2010 MAY 31, 2010
108. ON MAY 1, 2010 MAY 31, 2010
2535, APRIL 5, 2010 MAY 2, 2010
999, MARCH 1, 2010 MAY 2, 2010
Thank you
ToddHello
I see it; you want to look at only the last set of overlapping lines for each id, where the definition of "overlap" is extended such that two rows are expected to overlap if the line later begins between 0 and 24 hours after the end of the previous.
So what I posted was a bit off; Need to add a WHERE clause to not take into account that the last series of overlapping lines. Which would be to change the FROM clause to use, not the table, but something that indicates whether a line is in the last together or not, and this is the interesting part. We can use analytical functions (I used MIN in the example below) to determine if a game begins with a certain rank, then we can use other analytical functions (such as SUM) to see how many series began, and therefore, what game of any line belongs.
WITH got_new_grp AS ( SELECT id, start_date, end_date , CASE WHEN end_date < MIN (start_date) OVER ( PARTITION BY id ORDER BY start_date ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING ) - 1 THEN 1 ELSE 0 END AS new_grp FROM my_data ) , got_grp AS ( SELECT id, start_date, end_date , SUM (new_grp) OVER ( PARTITION BY id ORDER BY start_date DESC ) AS grp FROM got_new_grp ) SELECT id , MIN (start_date) AS start_date , MAX (end_date) AS end_date FROM got_grp WHERE grp = 0 GROUP BY id ORDER BY id ;
Output of your sample data:
. ID START_DATE END_DATE ---------- ----------- ----------- 108 01-May-2010 31-May-2010 445 01-Jan-2010 06-Aug-2010 658 01-Jan-2010 31-May-2010 999 01-Mar-2010 02-May-2010 2535 05-Apr-2010 02-May-2010 2710 01-May-2010 31-Aug-2011
Given that this problem is the last set of rows for each id, I counted sets in order from the last to the first.
I consider a row of "from" a group if she finished more than 24 hours before all the lines that begin beginning later. Subquery got_new_grp sets new_grp to 1 for these lines. new_grp is 0 for all lines that overlap with a few lines later departure.Published by: Frank Kulash, June 11, 2010 12:30
-
Hello
I have the rest of the table. I want to merge the date ranges if dates are continuous and the value is the same. I use Oracle 10 g. Help, please.
START_DATE END_DATE VALUE
----------------------------------------------------------------
1/1/2008 12/31/2008 1234
1/1/2009 12/31/2009 1234
Exit statement SQL must be as follows:
START_DATE END_DATE VALUE
----------------------------------------------------------------
1/1/2008 12/31/2009 1234
Thanks in advance.
Published by: user3898545 on January 27, 2010 19:44Hello
user3898545 wrote:
Hello
Dates will not overlap but sometimes start_date can be equal to end_date in a row.Sorry, I'm not sure of that figure.
If the query I posted is not giving correct results, post some samples (CREATE TABLE and INSERT statements are best, but a clause WITH as Tubby displayed is correct) and the correct results, you need these data.Please suggest if something needs to be done through pl/sql performance is also the key.
I don't see how the PL/SQL will help in this problem.
When two lines need to be combined, the end_date ranked sooner than always exactly 24 hours before the start_date on the line later?
If so:WITH got_grp AS ( SELECT data.* , end_date - SUM (end_date + 1 - start_date) OVER ( PARTITION BY val ORDER BY start_date ) AS grp FROM data ) SELECT MIN (start_date) AS start_date , MAX (end_date) AS end_date , val FROM got_grp GROUP BY val , grp ORDER BY val , start_date ;
Published by: Frank Kulash, 28 January 2010 14:03
For example, a subquery added. -
Count unique dates in a date range
Hey all - I need to count the number of unique of a column of dates dates. The complication is that I only need the unique dates associated with a particular person. Here is an example:
In this example, Bob has 5 single dates associated with his name, Jane has 4, and Doug has 2. When the list is short, like this, I can count just straight up, but more often that otherwise, I have a list of 1000 + lines long, often with dates outside the range that I've specified, so I need a formula.
Any help is appreciated. Let me know if this isn't enough information, or if you have a question for clarification. Thanks in advance for the help.
OS X 3.6.2 numbers 10.10.5,.
Hi Moose,
You want to count the number of dates separate for which there is at least one record of Bob and to do the same type of count for each others. only single date on the table (and this is unique only in the context of column A in the table) are in line 2 and line 5. All other dates in the column occur at least twice.
This table uses an index column that will contain the names to be counted. The highlight is not necessary; It's a Visual check that I used to match the number of Visual with that calculated in column G.
Two formulas are used, one to create the index values in column D, the other to perform counts in column G.
D2: = IF (COUNTIFS(A$1:A2,A2,C$1:C2,C2) = 1, C2"," ")
COUNTIF uses two test-values, pairs of condition to determine the number of times where this date-name pair has been entered upward at this line in the table and include the line in the account only if the two conditions return TRUE
- A$ 1: A2, A2: the date on the line (in the range $1 to "the line") is the same as the date in A2 ("this line of the column A")
- C$ 1: C2, C2: the text on the line (in the range 1 $ CAN to 'this line') is the same as the text in C2 ("this line of column C")
The County is passed back to IF.
IF it is equal to 1, fits the text (name) on this "line" column D, where it can later be counted.
IF the meter is not 1, IF inserts a null string in 'the line' from column D.
The formula is filled down to the end of column D and generates the displayed list.
G5: = COUNTIF (A"> =" & $ 2, A G, "< ="& G$ 3, D, "=" & F5)
COUNTIF employs here three test-values, pairs of condition. Again, all this should return TRUE for a row to be included in the count.
- A"> =" & G$ 2: the date in column A is as of the date in cell G2 "
- A"< =" & G$ 3: the date in column A is on or before the date in the G3 cell "
- D, '=' & F5: the text (name) in column D is the same as the text (name) to F5 ("this line of column F")
The count is returned to the cell containing the formula.
The formula is a city filled with the line containing the name in the list of names in column F.
Can be found in the features list, is also noted on visible when COUNTIF = is entered into a cell on the table.
Kind regards
Barry
-
To add totals in a certain date range
I have 3 sheets. Income, expenses and then an annual journal (has twelve columns, one for each month). Is there a way to get the numbers to add totals to a column of the spreadsheet of spending within the date range 01/01/16 and 31/01/16 and put the total in a cell in January on my sheet of each year. I can't understand a formula so that it can find the date range. I get a synyax error message.
Assumptions:
Your TABLES (not the leaves) are named income, spending and summary. Here is any other tables in the document with these names.
Dates of expenditure are in column A of the table expenses. Other than the header line, all the entries in this column are values Date and time that have been entered as dates only.
The amount for each item of expenditure is in column C of the expense table.
Line 1 of the analytical table is defined as a header line.
January is in column A of the summary table.
Summary::A1 cell contains the date January 1, 2016, but can be formatted to display only the name of the month or the month and year. (but see the note below) *.
Enter the formula in the cell that will contain total expenditures recorded with dates in January 2016 below:
= SUMIFS ("Expenses: Expenses, $C: $A," > = "& A1, Expenses: $A," < = "& EOMONTH(A1,0))
Example: All the amounts of expenditure were reduced to 1.00 simple confirmation of funds.
* NOTE: The formula has previously worked with the format of the cells in the row 1 Summary defined to show only the month and the year (two digits) of the effective date values (the first day of the month indicated), but the table I built tonight January 1, 2015 to the format to display 16 Jan, one was interpreted as January 16 (2016) , and SUMIFS formula did not include not January 1 to January 14 numbers in January total.
A custom, displaying the month (short or long) and the year (four digits) or a custom format shows only the name of the month (short or long) gave good results.
Note that any format under control of the display, the effective date is the first of the month displayed.
Table built and tested in Numbers ' 09 (v 2.3)
Kind regards
Barry
-
Conditional formatting depends on the date ranges
Basically, I want to be able to enter a date in column A and a sum of money in the B column, depending on where the date in column A grave in a date range, I want the money in column B to copy to a corresponding column. Is this possible? The only questions I found on here deal in a conditional formatting with dates have to do with derivative.
Thank you
Julio
I hope this help to clarify for you...
It is not bringing conditional formatting. Formatting conditional would change the format of a cell (or cells)... as the font, color, size, color cell background, or other formatting character is tics of a cell based on the contents of the cell
You ask about including of the value of a cel another beach under certain conditions
Here is an example:
The first three rows are header lines.
You must enter a valid date for the towing job. Using the format "mm/dd/yyyy".
C4 = IF (AND (DATEVALUE (A4) ≥DATEVALUE($B$1), DATEVALUE (A4) ≤DATEVALUE($B$2)), B4, "")
It's shorthand dethrone select cell C4, and type (or copy and paste it here) the formula:
= IF (AND (DATEVALUE (A4) ≥DATEVALUE($B$1), DATEVALUE (A4) ≤DATEVALUE($B$2)), B4, "")
Select the cell C4, copy
Select cells C4 at the end of the C column, paste
Maybe you are looking for
-
Qosmio E-10 gel once or twice daily
My Qosmio E-10 has a few problems:1. it freezes to the top once or twice daily. I've updated the BIOS and re-installed Windows already, but it does not help.2. is it possible to upgrade the Qosmio E-10?3. If I install Win MCE 2005 would be my E-10 wo
-
transfer my SL to Yose iTunes music
I have a large collection of songs in iTunes in international. Recently, I installed an SSD on my iMac with Yosemite and I want to transfer all of my collection (to the iTunes of Yosemite). How can I make this transfer so that I do not lose the attri
-
My problem is the radio I have an iphone 6 on AT & T running ios 9.2.1 I set my alarm at 02:45 it exploded at 3:45 even though when I checked once again it still says 02:45 Why the alarm did not keep even if time went an hour before I find this stran
-
Cannot use remote desktop in Win Server 2008 r2 server
I installed a Win Server 2008 r2 server and I am unable to use RD to access, firewall is turned off, RD config is configured to accept all versions what to do?
-
How can I disable the screen keyboard on?
original title: keyboard display I have activated a keyboard screen on my monitor & would like to disable this function, how do I do this?