Look for the date range
Table data and the sample are as mentioned below. I have 2 dates ' 4 / 14/2010 (Date1)' and ' 4 / 25/2010 ' (Date2). Need to retrieve all the rows present in this range.that Date1 and Date2 must be greater than or equal to the start date and less than or equal to the end date.
CREATE TABLE test_1
(
ID VARCHAR2(4000 BYTE),
DESCRIPTION VARCHAR2(500 BYTE),
START_DT DATE,
END_DT DATE
)
Insert into TEST_1
(ID, DESCRIPTION, START_DT, END_DT)
Values
('1', 'Apple', TO_DATE('03/01/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/31/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TEST_1
(ID, DESCRIPTION, START_DT, END_DT)
Values
('2', 'Ball', TO_DATE('03/04/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/17/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TEST_1
(ID, DESCRIPTION, START_DT, END_DT)
Values
('3', 'Cat', TO_DATE('04/13/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/30/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TEST_1
(ID, DESCRIPTION, START_DT, END_DT)
Values
('4', 'Dog', TO_DATE('04/21/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/28/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TEST_1
(ID, DESCRIPTION, START_DT, END_DT)
Values
('5', 'Elephant', TO_DATE('04/22/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/27/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TEST_1
(ID, DESCRIPTION, START_DT, END_DT)
Values
('6', 'Fox', TO_DATE('04/14/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('05/18/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Hello
Thanks for posting the sample data in a useful form. It is very useful.
You should also post the results desired from these data. That can be useful too, especially when the description is vague, because this description is:
user13024762 wrote:
Table data and the sample are as mentioned below. I have 2 dates ' 4 / 14/2010 (Date1)' and ' 4 / 25/2010 ' (Date2). Need to retrieve all the rows present in this range.that Date1 and Date2 must be greater than or equal to the start date and less than or equal to the end date.
To find all lines where the two
Date1 is greater than or equal to the start date and less than or equal to the maturity, and
Date2 is greater than or equal to the start date and less than or equal to the end date
WITH params AS
(
SELECT TO_DATE ( '04/14/2010 00:00:00'
, 'MM/DD/YYYY HH24:MI:SS'
) AS Date1
, To_DATE ( '04/25/2010 00:00:00'
, 'MM/DD/YYYY HH24:MI:SS'
) AS Date2
FROM dual
)
SELECT *
FROM test_1 t
JOIN params p ON p.Date1 BETWEEN t.start_dt
AND t.end_dt
AND p.Date2 BETWEEN t.start_dt
AND t.end_dt
;
Output:
ID DESCRIPTIO START_DT END_DT DATE1 DATE2
-- ---------- ------------------- ------------------- ------------------- -------------------
3 Cat 04/13/2010 00:00:00 04/30/2010 00:00:00 04/14/2010 00:00:00 04/25/2010 00:00:00
6 Fox 04/14/2010 00:00:00 05/18/2010 00:00:00 04/14/2010 00:00:00 04/25/2010 00:00:00
Tags: Database
Similar Questions
-
by selecting specific days of the week for the date range?
I have a table with a number of clients for about a year, but I want to only select Wednesday and Thursday of
every week, since the beginning of the dates. Table is simple and has two columns. Each line is separate from a Date
There is no duplicate of Date, it is counted for every day of the year.
column 1: number of clients, count (customer_id)
column 2: Date
Need help with the best way to achieve this.
Not sure if it is even possible to select a date in the name of the day?
Basically, I want to select every Wednesday and Thursday of each week and compare the counts during the week, the week during
week for the whole week see if charges go upwards or downwards, to get trends, thank you!Hello
Kodiak_Seattle wrote:
I have a table with a number of clients for about a year, but I want to only select Wednesday and Thursday of
every week, since the beginning of the dates. Table is simple and has two columns. Each line is separate from a Date
There is no duplicate of Date, it is counted for every day of the year.column 1: number of clients, count (customer_id)
column 2: DateNeed help with the best way to achieve this.
Not sure if it is even possible to select a date in the name of the day?
Sorry, we don't know what you want.
To see if a date given (dt) is a Wednesday or Thursday, you can use:
WHERE TO_CHAR ( dt , 'DY' , 'NLS_DATE_LANGUAGE=ENGLISH' -- If necessary ) IN ('WED', 'THU')
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002} -
SUM (case use this structure to get average values on the date range
I use:
Oracle SQL Developer (3.0.04) build hand - 04.34 Oracle Database 11 g Enterprise Edition 11.2.0.1.0 - 64 bit Production
How do we use the function sum with a structure of matter inside.
so I gave that looks like have an ID, date and value. I'm looking to get the day 7 medium for the date range of 04/01/2013 to 20/04/2013
* Please let me know if the table does not load.with t as ( select 1 ID_Key,to_date('4/1/2013','mm-dd-yyyy') date_val, 10 Value_num from dual union all select 1 ID_key,to_date('4/2/2013','mm-dd-yyyy'), 15 from dual union all select 1 ID_key,to_date('4/3/2013','mm-dd-yyyy'), 20 from dual union all select 1 ID_key,to_date('4/5/2013','mm-dd-yyyy'), 0 from dual union all select 1 ID_key,to_date('4/8/2013','mm-dd-yyyy'), 12 from dual union all select 1 ID_key,to_date('4/9/2013','mm-dd-yyyy'), 8 from dual union all select 1 ID_key,to_date('4/10/2013','mm-dd-yyyy'), 6 from dual union all select 1 ID_key,to_date('4/12/2013','mm-dd-yyyy'), 10 from dual union all select 1 ID_key,to_date('4/13/2013','mm-dd-yyyy'), 0 from dual union all select 1 ID_key,to_date('4/14/2013','mm-dd-yyyy'), 0 from dual union all select 1 ID_key,to_date('4/15/2013','mm-dd-yyyy'), 10 from dual union all select 1 ID_key,to_date('4/16/2013','mm-dd-yyyy'), 5 from dual union all select 1 ID_key,to_date('4/17/2013','mm-dd-yyyy'), 2 from dual union all select 1 ID_key,to_date('4/20/2013','mm-dd-yyyy'), 3 from dual union all select 2 ID_key,to_date('4/3/2013','mm-dd-yyyy'), 12 from dual union all select 2 ID_key,to_date('4/5/2013','mm-dd-yyyy'), 15 from dual union all select 2 ID_key,to_date('4/6/2013','mm-dd-yyyy'), 5 from dual union all select 2 ID_key,to_date('4/7/2013','mm-dd-yyyy'), 7 from dual union all select 2 ID_key,to_date('4/9/2013','mm-dd-yyyy'), 10 from dual union all select 2 ID_key,to_date('4/11/2013','mm-dd-yyyy'), 5 from dual union all select 2 ID_key,to_date('4/12/2013','mm-dd-yyyy'), 0 from dual union all select 2 ID_key,to_date('4/13/2013','mm-dd-yyyy'), 0 from dual union all select 2 ID_key,to_date('4/15/2013','mm-dd-yyyy'), 6 from dual union all select 2 ID_key,to_date('4/16/2013','mm-dd-yyyy'), 8 from dual union all select 2 ID_key,to_date('4/17/2013','mm-dd-yyyy'), 0 from dual union all select 2 ID_key,to_date('4/18/2013','mm-dd-yyyy'), 10 from dual union all select 2 ID_key,to_date('4/19/2013','mm-dd-yyyy'), 5 from dual )
I would get the average of 7 days, as long as there is date for the rank of enough previous dates, is it not, then it returns a null value.
the results should look like this
As you can see, there are gaps in the dates, the value is then processed by zeros for the 7Day_Avg and then ignored for the 7Day_Avg2 (not counted in the number of days on average do to no valu_num line)ID_Key date_val Value_num 7Day_Avg 7Day_Avg2 1 4/1/2013 10 null null 1 4/2/2013 15 null null 1 4/3/2013 20 null null 1 4/5/2013 0 null null 1 4/8/2013 12 6.71 11.75 1 4/9/2013 8 5.71 10.00 1 4/10/2013 6 3.71 6.50 1 4/12/2013 10 5.14 9.00 1 4/13/2013 0 5.14 7.20 1 4/14/2013 0 5.14 6.00 1 4/15/2013 10 4.86 5.67 1 4/16/2013 5 4.42 5.17 1 4/17/2013 2 3.85 4.50 1 4/20/2013 3 2.86 4.00 2 4/3/2013 12 null null 2 4/5/2013 15 null null 2 4/6/2013 5 null null 2 4/7/2013 7 5.57 9.75 2 4/9/2013 10 7.00 9.80 2 4/11/2013 5 6.00 8.40 2 4/12/2013 0 3.86 5.40 2 4/13/2013 0 3.14 4.40 2 4/15/2013 6 3.00 4.20 2 4/16/2013 8 2.71 3.80 2 4/17/2013 0 2.71 3.17 2 4/18/2013 10 3.43 4.00 2 4/19/2013 5 4.14 4.83
I tried something like this at first, but becomes "missing keyword" error
Should I have the structure outside the sum function?select t.*/, sum( case when date_val between :day2 - 6 and :day2 then value_num between date_val - 6 and date_val else null end ) as 7Day_avg form t
Any thoughts?
Published by: 1004407 on June 7, 2013 11:06Hello
If you want to calculate the average of the last 7 days, including the current day, then then RANGE should be 6 PRIOR, not 7.
Try this:
WITH got_min_date_val AS
(
SELECT id_key, date_val, value_num
MIN (date_val) compared to (AS min_date_val)
T
WHERE the date_val BETWEEN TO_DATE (April 1, 2013 ', "dd-mm-yyyy")
AND TO_DATE (April 20, 2013 ', "dd-mm-yyyy")
)
SELECT id_key, date_val, value_num
CASE
WHEN date_val > = min_date_val + 6
THEN SUM (value_num) OVER (PARTITION BY id_key
ORDER BY date_val
PRIOR TO TIER 6
)
/ 7
END AS avg_7_day
CASE
WHEN date_val > = min_date_val + 6
THEN AVG (value_num) OVER (PARTITION BY id_key
ORDER BY date_val
PRIOR TO TIER 6
)
END AS avg_7_day_2
OF got_min_date_val
ORDER BY id_key
date_val
;
Output:
ID_KEY DATE_VAL VALUE_NUM AVG_7_DAY AVG_7_DAY_2
---------- --------- ---------- ---------- ------------
1 1 APRIL 13 10
1 2 APRIL 13 15
1 APRIL 3, 13 20
1 5 APRIL 13 0
1 APRIL 8, 13 12 6.71 11.75
1 APRIL 9, 13 8 5.71 10.00
1 APRIL 10 13 6 3.71 6.50
1 12 APRIL 13 10 5.14 9,00
1 13 APRIL 13 0 5,14 7.20
1 14 APRIL 13 0 5,14 6.00
1 15 APRIL 13 10 4.86 5.67
1 16 APRIL 13 5 4.43 5.17
1 APRIL 17, 13 2 3.86 4.50
1 APRIL 20, 13 3 2.86 4.00
2 APRIL 3, 13 12
2 5 APRIL 13 15
2 6 APRIL 13 5
2 7 APRIL 13 7 5.57 9.75
2 9 APRIL 13 10 7,00 9.80
2 11 APRIL 13 5 6.00 8.40
2 12 APRIL 13 0 3.86 5.40
2 13 APRIL 13 0 3.14 4.40
2 15 APRIL 13 6 3.00 4.20
2 16 APRIL 13 8 2.71 3.80
2 17 APRIL 13 0 2.71 3.17
2 18 APRIL 13 10 3.43 4.00
2 APRIL 19, 13 5 4.14 4,83
Post edited by: FrankKulash
Sorry; I wanted to respond to OP, not Greg
-
Get the date range min/max for consecutive events.
Hi all...
I am fairly new to the programming of the DB and is working on some examples I picked up a few places. The database version is 10g R2.
I would like to configure the data here and I can explain my requirement.
create table table_1 (product_id varchar2(25), region_id number, event_id number event_date date, event_status number(1)) /
Now the data because it is->
insert into table_1 values ('Prod-1',10, null, to_date('01-feb-2014','dd-mon-yyyy'),null) / insert into table_1 values('Prod-1',10, 1001, to_date('10-mar-2014','dd-mon-yyyy'), 1) / insert into table_1 values('Prod-1',10, 1001, to_date('20-mar-2014','dd-mon-yyyy'), 3) / insert into table_1 values('Prod-1',10,1002, to_date('01-apr-2014','dd-mon-yyyy'), 1) / insert into table_1 values('Prod-1',10, 1002, to_date('10-apr-2014','dd-mon-yyyy'), 3) / commit /
If the table now contains the following data
select * from table_1;
PRODUCT_ID REGION_ID EVENT ID EVENT_DAT EVENT_STATUS
------------------------- ---------- -------- --------- ------------
Prod-1 10 1 February 14
Prod-1 10 1001 10 March 14 1
Prod-1 10 1001 20 March 14 3
Prod-1 10 1002 1 April 14 1
Prod-1 10 1002 April 10, 14 3
Now, the condition is as follows:
Above is the dates start and end for the tests on a product in a given region. The event_status column indicates the dates of beginning and end. Event_status = 1, for the date of beginning and the event_status = 3 of the end date.
A new event is now coming from March 21 and ending on March 31.
The power required is a product identifier / region; If there are events that are ending and then count the days, for example, 1001 to end on March 20, but now the new event begins on 21 March... and the new event ends on 31 March and event 1002 begins 01 - Apr... and so on.
The output required for this is as follows:
PRODUCT_ID REGION_ID EVENT_MIN_DATE EVENT_MAX_DATE
------------------------- ---------- -------------- --------------
Prod-1 10 10 14 March 10 April 14
The output should give a product identifier / region, when events are immediately after the other, out the min date of beginning and end of max for all these manifestations of "back to back".
Now I wrote the code for this, but it goes into a purely 'loop' for application in PLSQL... But my head tells me that if the results are correct. the PLSQL implementation is not the most efficient and effective way.
Can someone help me to form the query? I tried to use functions analytical min/max but it gives me the start and end dates back even if my events are not "back to back" or previous/succeed each other... so my query result is not quite correct.
Am reading on the TYPE clause but would be grateful if someone could help me with this query... or any other form better to implement this event so PLSQL can be used. The database version is 10g R2.
Thank you
K
PS - The number of such events back to back is limited to 4 and the events could be created in any order. But if someone could help me with the scenario above; am sure I could make a request addressed to any change in the order. :-)
No this isn't a recursive with clause, perhaps the UNION ALL you got confused. She will work with 10g.
Since there are 2 tables that you said, the block all_data brings together only the lines of the two tables. table_1 start_date and end_date are built from the event_status (where the max in group by).
-
On the date ranges in search of oracle forms
I use service number, name, type person and date as search criteria in the custom form ranges.
When I enter the employee number, press the search button, I get the exact info in the block of result.
Result block contains
name of the employee, personid, emp numbed, org, start_date.
Similarly when I enter the employee number, dept, I get the correct values.
My question is, when I enter the date range. IAM unable to filter the data.
When I enter START_DATE between nvl(:BLOCKNAME.) Start_date, 1 January 1901 ') and nvl(:BLOCKNAME.) End_date, 31-DEC-4712') where block clause in the result. I had data for the range of dates also.
If I give condition in where clause results take so long when I search with the name of the employee, number, dept, person type.
If I have a query with the date, the persormance is good.
Think you know everything, how it prevents START_DATE between nvl(:BLOCKNAME.) Start_date, 1 January 1901 ') and nvl(:BLOCKNAME.) End_date, 31-DEC-4712') when look us with the employee's name, number, dept, person type.So leave the WHERE clause of your empty block and put something like the following in your search button:
IF :BLOCK.START_DATE IS NOT NULL OR :BLOCK.END_DATE IS NOT NULL THEN SET_BLOCK_PROPERTY('YOURBLOCK', ONETIME_WHERE, 'START_DATE between nvl(:BLOCKNAME.START_DATE,TO_DATE(''01-JAN-1901'', ''DD-MON-YYYY'')) and nvl(:BLOCKNAME.END_DATE,TO_DATE(''31-DEC-4712'', ''DD-MON-YYYY''))'); END IF;
-
Looking for the link to download HDD Recovery for Satellite L630
Hi all
I'm looking for the DOWNLOAD LINK of recovery of HARD drive to my new Toshiba L630 laptop.
I read in several positions and the manuals it should be already on my hard drive.
But this isn't on my hard drive, where it is connected with the restoration of the system, I even created a system restore disk, but there is no trace of any disk HARD Recovery Utility.This is the list of files create
# Created on 2011-03-15 04:00 with Lister directory v0.9
Name size Date time Attr
e:\ (1) 175 703 783 -----
2011-03-12 16:27 r-
2011-03-12 16:27 r-
Bootmgr 383 562 2011-03-12 16:27 r -.e:\boot\ (3) 3 433 472 2011-03-12 16:27 r -.
BCD 262 144 2011-03-12 16:27 r -.
BootFix.bin 1 024 2011-03-12 16:27 r -.
Boot.SDI 3 170 304 2011-03-12 16:27 r -.e:\sources\ (1) 171 886 749 2011-03-12 16:27 r-
Boot.wim 171 886 749 2011 - 03 - 12 16:27 r -.Hello
HARD drive recovery can not be downloaded.
You can not download the recovery disc as well.Generally, recovery disc HARD must be available on your laptop and you should be able to start this pressing F8 at the beginning of the initialization.
Simply said: turn on the device, press F8 immediately after the laptop was turned on maybe you will have to press F8 several times in the line
Then choose fix my computer and then you should see the drive HARD recovery option.If this is not available (no matter why), then you must create a recovery disc using called Recovery disk Creator tool that must be preinstalled on the laptop.
If you are not able to create the recovery disk then you can order it from here:
http://backupmedia.Toshiba.EU/landing.aspx -
"Look for the update is not available at this time. Try again later. »
I use a Photon on the Sprint 3 G EVDO network. When I open the settings app and click the option to check the software update from Motorola, the following screen appears: "look for the update is not available at this time. Try again later. "When I'm on a Wi - Fi network, a similar message appears (no screenshots):" your device is up to date! No update is necessary at this time. "Can someone please provide more information about what exactly is the message originally in my screenshot below to appear? Thank you for your help.
If you go to Menu > settings > Data Manager > delivery data > social apps > Sync only over wifi. If this box is checked, and that you are connected to 3g / 4g and no wifi, you will get the server is not available because you are not connected to our servers. As soon as you connect to the wifi it reconnect to our servers and see no upgrade is available or an update if one is available. Your phone works as expected.
Mark
Support Forums Manager
-
What is the minimum value for the data type double?
... a more academic question: what is the minimum value of the data type double? I thought 'double', it is the 8-byte IEEE standard and what I remember, it's + - 1.7E + - 308. The more different number of 0 should be 1.797E - 308.
This is why I was a little surprised when I looked at the data output of my calculation of CVI, where I found the numbers with exponents of E-319 or E-324 as the smallest value...
But I'm sure there's an explanation :-)
Thank you for sharing with me,
Wolfgang
The largest number is indeed the order of + 1.7E + 308; There are a smaller number of - 1.7E + 308. Note that this is in fact the most negative number, which is the smallest by some reckoning. For the small beach of the Exhibitor, things get a little more complicated. 1E-308 can be represented with complete accuracy and resolution, but if you're willing to lose a few bits of precision, you can go down even further. For example:
Double x, y, z:
x = 1E-300;
y = 1E7;
z = x / y; Give 1.000000000000000E - 307
y = 1E8;
z = x / y; Give 9.999999999999999E - 309
y = 1E18;
z = x / y; Give 9.999987484955998E - 319
y = 1E23;
z = x / y; Give 9.881312916824931E - 324
So, as you can see, values less than 1E-308 are possible, but they become increasingly more inaccurate and should not be relied upon.
JR
-
HP Photosmart more B210A Laptop will not recognize when looking for the device
I struggled to connect my laptop with the printer. Whenever I look for the printer when trying to connect it never comes up as an option to connect. All other printers come in range but not this one. If anyone has a solution thanks in advance.
Hi QPR1882,
What is the operating system on your computer?
The printer has an IP address assigned?
If Yes, what is the IP address assigned?
HP has designed a quick and easy tool that diagnoses and solves many problems of printing, scanning and connectivity: The HP Print and Scan doctor. HP recommend you to download and install Print and scan doctor no matter what time you need to solve a problem with your HP printer from the link below. I would like to know what are the errors you receive?
-
With the help of case condition for the date of distinct values is does not
Hello PL/SQL gurus and experts.
I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
I followed two tables
TT3-
TT4create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select 1,11,21,'Mike',25 from dual union all select 2,12,22,'Clark',26 from dual union all select 4,17,27,'Ussan',28 from dual union all select 5,13,21,'Linda',29 from dual union all select 6,14,24,'Obrek',35 from dual union all select 7,15,25,'Batty',45 from dual union all select 8,16,26,'Nicky',38 from dual;
Now, if I use the following DML for the year 2012, then the result is as follows-drop table TT4; create table TT4(TRNID,BlockID,FeesCntlr,CommCntlr,LatePayCntlr,BookDate) as select 221,625,1,11,21,20121101 from dual union all select 223,625,2,12,22,20121101 from dual union all select 224,625,1,11,21,20121101 from dual union all select 225,627,4,17,27,20111001 from dual union all select 226,628,5,13,21,20120701 from dual union all select 227,628,6,14,24,20120701 from dual union all select 334,628,7,15,25,20120701 from dual union all select 339,629,8,16,26,20120701 from dual union all select 393,629,1,11,21,20120701 from dual union all select 432,629,2,12,22,20120701 from dual union all select 347,629,1,11,21,20120701 from dual union all select 556,629,4,17,27,20120701 from dual union all select 558,629,5,13,21,20120701 from dual union all select 974,629,6,14,24,20120701 from dual union all select 976,629,7,15,25,20120701 from dual union all select 980,629,8,16,26,20120701 from dual union all select 1223,650,2,12,22,20110415 from dual union all select 1224,650,1,11,21,20110415 from dual union all select 1225,650,4,17,27,20110415 from dual union all select 1226,650,5,13,21,20110415 from dual union all select 1227,650,6,14,24,20110415 from dual union all select 1334,650,7,15,25,20110415 from dual union all select 1339,710,8,16,26,20120115 from dual union all select 1393,710,1,11,21,20120115 from dual union all select 1432,710,2,12,22,20120115 from dual union all select 1347,710,1,11,21,20120115 from dual union all select 1556,710,4,17,27,20120115 from dual union all select 1558,711,5,13,21,20111231 from dual union all select 1974,711,6,14,24,20111231 from dual union all select 1976,711,7,15,25,20111231 from dual ;
Now, if I use the following DML for 2011, then the result is as follows-SQL> select t3.Name,t3.age,count(t4.TRNID),count(distinct(BlockID)) from 2 tt3 t3,tt4 t4 3 WHERE t3.feescntlr = t4.feescntlr 4 AND t3.commcntlr = t4.commcntlr 5 AND t3.latepaycntlr = t4.latepaycntlr 6 AND t4.bookdate between 20120101 and 20121120 7 GROUP BY t3.name, t3.age; NAME AGE COUNT(T4.TRNID) COUNT(DISTINCT(BLOCKID)) ----- ---------- --------------- ------------------------ Mike 25 12 3 Mike 27 12 3 Batty 45 4 2 Clark 26 6 3 Linda 29 4 2 Nicky 38 6 2 Obrek 35 4 2 Ussan 28 4 2 8 rows selected.
But by using the condition if I use the following dml and results do not match-SQL> select t3.Name,t3.age,count(t4.TRNID),count(distinct(BlockID)) from 2 tt3 t3,tt4 t4 3 WHERE t3.feescntlr = t4.feescntlr 4 AND t3.commcntlr = t4.commcntlr 5 AND t3.latepaycntlr = t4.latepaycntlr 6 AND t4.bookdate between 20110101 and 20111120 7 GROUP BY t3.name, t3.age; NAME AGE COUNT(T4.TRNID) COUNT(DISTINCT(BLOCKID)) ----- ---------- --------------- ------------------------ Mike 25 2 1 Mike 27 2 1 Batty 45 2 1 Clark 26 2 1 Linda 29 2 1 Obrek 35 2 1 Ussan 28 4 2 7 rows selected.
As the expected output, that I expect - isSQL> select Name,Age,sum(Trn),sum(CurYrOrdr) "2011 Order", sum(LastYrOrdr) "2012 Order" 2 from 3 ( 4 select t3.Name,t3.age,count(t4.TRNID) Trn,(case when t4.bookdate between 20110101 and 20111231 then count (distinct(BlockID)) else 0 end) CurYrOrdr, 5 (case when t4.bookdate between 20120101 and 20121120 then count (distinct(BlockID)) else 0 end) LastYrOrdr 6 from 7 tt3 t3,tt4 t4 8 WHERE t3.feescntlr = t4.feescntlr 9 AND t3.commcntlr = t4.commcntlr 10 AND t3.latepaycntlr = t4.latepaycntlr 11 AND t4.bookdate between 20110101 and 20121120 12 GROUP BY t3.name, t3.age,t4.bookdate 13 ) 14 group by Name,Age order by Name,Age; NAME AGE SUM(TRN) 2011 Order 2012 Order ----- ---------- ---------- ---------- ---------- Batty 45 8 2 2 Clark 26 8 1 3 Linda 29 8 2 2 Mike 25 14 1 3 Mike 27 14 1 3 Nicky 38 6 0 2 Obrek 35 8 2 2 Ussan 28 8 2 2 8 rows selected.
I sincerely thank each of you in advance for the input/comments that I fight with it for some time now.---------------------------------- Expected Output - NAME AGE "2012 TRNID" "2011 TRNID" "2012 ORDERID" "2011 ORDERID" ----- ---------- --------------- ----------------------------- ---------- ------------ Mike 25 12 2 3 1 Mike 27 12 2 3 1 Batty 45 4 2 2 1 Clark 26 6 2 3 1 Linda 29 4 2 2 1 Nicky 38 6 2 2 1 Obrek 35 4 2 2 1 Ussan 28 4 4 2 2
Kindly help.user555994 wrote:
Hi JAC
Thanks for the comments and certainly once I comment out the following line.
- AND t4.bookdate between 20110101 and 20111120then the values are adapting, but at the same time why do we need to comment the date range condition as case is just a filter and not the condition.
filter should be-
AND t4.bookdate between 20110101 and 20121120 --"made it 12"
-
Get number of records in the date range - IDE: PLSQL Developer
I want to count the number of records of members who register within a date range specified, based on effective and expiration dates and their "elg_code". I posted the SQL code for some examples of data. What I would like to see returned is in three columns of the counties where the eff_date date_exp members fall within the date range specified by the SQL and have an Elg_code of ' ' (space).
So what I would like is all members with elg_code ' ' where he eff_dt and exp_dt range is April 2012, 2012 MAY & JUN 2012. Thus, according to data from the sample I posted, Mark, where his elg_code record is ' ', his eff_dt is 01/01/2011 and April 2012 (30/04/2012) is his exp_dt. Range of the brand statement may 2012, but not MAY or JUNE of 2012. Marty would tally for the APR and MAY because his eff_dt is before MAY 2012 and his exp to MAY 2012. etc...
According to the data below, the results should resemble:
APR MAY JUN
4-3-2
APR should have FRANK, MARK, MARTY, MARY.
MAY should have FRANK, MARTY, MARY
JUN should have FRANK and MARIE
NOAM and JOHN should not appear as his records with elg_code ' ' have no documents eff_dt and exp_dt which are April-June 2012.
So what I tried without success as it appears that I have a kind of Cartesian question (?), is:
Select count (m1.mbr_name) APR,
Count (m2.mbr_name) MAY,
Count (m3.mbr_name) JUN
mbr2 M1,
mbr2 m2,
mbr2 m3
"where m1.eff_dt < ' 01 - may - 2012"
"and m1.exp_dt > ' 01-Apr-2012.
and m1.elg_code = ' '
"and m2.eff_dt < 1 June 2012"
"and m2.exp_dt > ' 01 - may - 2012"
and m2.elg_code = ' '
"and m3.eff_dt < 1 July 2012"
"and m3.exp_dt > 1 June 2012"
and m3.elg_code = ' '
Here's the DML
Thanks for any help!
create table mbr2 (mbr_name varchar (10), varchar (1) grpid eff_dt date, date of exp_dt elg_code varchar (1))
Commit
insert into mbr2 values ('BRAND', 'A', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (April 30, 2012 ',' DD-MM-YYYY '), ' ')
insert into mbr2 values ('BRAND', 'A', to_date (May 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY '), 'C')
insert into mbr2 values ('MARTY', 'A', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (May 31, 2012 ',' DD-MM-YYYY '), ' ')
insert into mbr2 values ('MARTY', 'A', to_date (June 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY '), 'C')
insert into mbr2 values ('FRANK', 'B', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (June 30, 2012 ',' DD-MM-YYYY '), ' ')
insert into mbr2 values ('FRANK', 'B', to_date (July 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY ""), 'C')
insert into mbr2 values ('MARY', 'B', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (June 30, 2012 ',' DD-MM-YYYY '), ' ')
insert into mbr2 values ('MARY', 'B', to_date (July 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY ""), 'C')
insert into mbr2 values ('JOHN', 'C', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (July 1, 2011 ',' DD-MM-YYYY '), ' ')
insert into mbr2 values ('JOHN', 'C', to_date (July 1, 2011 ',' DD-MM-YYYY '), to_date (1 January 2012 ',' DD-MM-YYYY ""), 'C')
insert into mbr2 values ("NOAM" 'd', to_date (July 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY '), ' ' ")
CommitThis gives you a report for the current month and the two front. Column header must be adjusted ;-)
select count( case when eff_dt < add_months(trunc(sysdate,'MM'), -1) and exp_dt >= add_months(trunc(sysdate,'MM'), -2) then 1 end) April , count( case when eff_dt < add_months(trunc(sysdate,'MM'), 0) and exp_dt >= add_months(trunc(sysdate,'MM'), -1) then 1 end) May , count( case when eff_dt < add_months(trunc(sysdate,'MM'), 1) and exp_dt >= add_months(trunc(sysdate,'MM'), 0) then 1 end) June from mbr2 where elg_code = ' ' and eff_dt < add_months(trunc(sysdate,'MM'), 1) and exp_dt >= add_months(trunc(sysdate,'MM'), -2) APRIL MAY JUNE 4 3 2
-
I'm looking for the 1st working day of the week.
Hello
I'm looking for the 1st working day of the week except Saturday, Sunday and holidays. I have vacation, the name of the table that contains the columns HolidayDate and HolidayDescription.
Ex:
01/10/2011 is monday (i.e) 1st company day.check if it is in the host table, then return the result as 01/11/2011 other returns the output as a 11-1-2011(which is the first business day of this week).
Can someone tell me the query to solve?Hello
If dt is any DATE, it is the first day of work in the same week as dt:
WITH all_week AS ( SELECT TRUNC (dt, 'IW') + LEVEL - 1 AS a_dt FROM dual CONNECT BY LEVEL <= 5 ) SELECT MIN (a_dt) AS first_work_dt FROM all_week WHERE a_dt NOT IN ( SELECT holiday_dt FROM holiday ) ;
This assumes that you have never 5 consecutive days. (Where I work, holidays are always at least a week apart, so that's fine.)
If you have a week's holiday, increase the number of 'magical' in the CONNECT BY clause.It also means that holiday.holiday_dt = TRUNC (holiday.holiday.dt).
-
I'm looking for the Mac key combination which is equivalent to Alt + Tab in Windows that allows you to choose Open Windows (pass) but I can't find this info. I hope that someone will tell me what combination of keys and as a bonus, where I can find it in the menu help. Thank you!
The standard keyboard shortcuts are listed here:
Keyboard shortcuts in Mac - Apple Support
You can also define your own in System Preferences > keyboard
-
I am looking for the way that my invention
I am an inventor of VR technology. I know what may be in the future.
I have a tech for the VR game industry.
I am looking for the way to realize my ideas. Can you help me?
VR is the next big thing for the past 15 years. And yet...
-
Re: Satellite 1130-z24 - looking for the part number or a screen
Hello world
Never done this before, are looking for the part number or a screen for the z24 1130 above
help please.
Hi michael,.
In my opinion, you should contact an authorized service provider. Why? Guys can you tell the exact part number and order a new replacement screen for you. On the Toshiba site, you can search for them.
Alternative look on eBay. Here you can often get second hand spare parts. The screen is an expensive item so maybe you have a little luck on eBay.
Maybe you are looking for
-
Thunderbird 38, lightning and provider of Google
Hello Since the upgrade to TBird v.38.0.1 with lightnning v4.0.0.1 and Google Provider v 1.0.4 TBird crashes constantly. When I run in safe mode email seems to work very well.I've deleted and reinstalled Tbird and extensions of countless times.At thi
-
Can not see the person called in video conferencing
I had this problem on my Samsung original Tab and now on my new Pro tab. When I video call someone, I can't see them... the image on screen is me. The person I'm calling sees me but not themselves.If the other person calls me, everything works fine.
-
Can I dictate into a phone download in word document?
Can I dictate into a phone download in word document?
-
calculation of the checksum of the sum of
Hello T the world I am trying to diet to control a programmable Spellman via the RS232 connection that is connected to the PC under LABVIEW and pour it I must ORDER ASCII en code messages, and each message to calculate the chechsum (MUHC checksum) po
-
HP povilian g6: we know what housing is my hp povilian g6
What is housing type for my g6 hp povilian g6t - 1 d 00 product model is a1j18 av and new which is the type of housing thanks