Using SQL to display the date range
Gurus,I have a sql statement such as
select MIN(HIREDATE), MAX(HIREDATE) FROM EMP WHERE DEPTNO = 30
My output looks likeMIN(HIREDATE) MAX(HIREDATE)
12/30/1998 12/30/2001
Based on the values of MIN (HIREDATE), MAX (HIREDATE) valuesI need a SQL to generate the output as
30/12/1998
30/01/1999
28/02/1999
---
---
until the Max value (HIREDATE)
In February, we have 30 days, in this case to the last day of the month.
Thanks for the great help
C 007
Hello
put my post to correct and others with useful, please
Is salim.
Tags: Database
Similar Questions
-
SQL to display the results if the number of output is below a limit
I have a requirement where I can display the SQL result set if the number of records output is 1000 or less than that... otherwise raise a user-defined exception, say "Please change the search criteria. I can achieve this by GET the the number of SQL rows first and then re-run the same SQL to display the data if the number of rows is less than 1001. Could someone let me know if this is possible without re - run the SQL several times as the SQL is the query intensive re-source
Hello
You can try in bulk collect into a collection.
If the number of rows in the collection is less than 1000 triggers an application error or return results, if it is greater than 1000
If this is suitable for your needs, please post more information on the system requirements.
Kind regards
Cool
-
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
-
Search a directory of data and display the data that is within the range of dates
Hello
I have a full idrectory of data from overtime, and I think of search in the directory and display the data files for specific dates. I only started this encoding yet but I figure I'll take the brain of some SMEs here labview and start in the right direction. My goal is to go through a comprehensive directory of data taken for a month or MORE csv files and select the data to process and display office files the date of its registration. If I take the data of last week, last month or last minute, it should just treat as an exact or more.
Please help me get started on the right foot
End date will be probably greater than the start date, right? So, end date must connect at the entrance to the upper limit. Then wire in the range? to the conditional terminal of a tunnel of conditional indexation.
Lynn
-
is it possible to display the Date and time in the address bar or a clock window constantly
I need to take screenshots with date stamps and time using the script of iMacros. Everything by taking screenshots iMacro don't add taskbar windows for the date and time. It takes screenshots of browser. Is it possible to display the Date and time in the address bar or a clock within the tab browser constantly to capture the screenshot with time stamp through iMacros
I added the big clock background Add-ons, but it is visible to new tabs.Badly looking for help and it will be really appreciated...
Try this extension:
-
A drop-down list in Axapta 4.0 box takes longer to display the data.
Hi all
I have a drop-down list box in Axapta 4.0, which takes about 10 seconds to display the data. The area of cobo contain the minimum data to be displayed. However, it takes more time than necessary. How to fix... Help me!
Hello
1. what operating system do you use?
2 did you change on your computer?
I suggest you follow the link and check.
How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7
http://support.Microsoft.com/kb/929135
Note: After a repair, be sure to set the computer to start as usual as mentioned in step 7 in the above article.
I also suggest that you send your request from the link and check.
-
Want to access a SOAP service and display the data in the external list
Hello
I could see a WCF Service via the type of external content successfully. Now I want to access a SOAP Service and display the data in an external list in Sharepoint 2010. I am able to create a data source with success with the SOAP service, but how to display the data in the external list as external list uses only as data sources for external content types.
Also with WCF as external content type, it is only on WCF services or any kind of web services can be added as an external content type.
Any help would be appreciated.
Thanks in advance
Hello sunny198218,
The question you have posted is related to Windows Communication Foundation Service and would be better suited in the MSDN forum for category Windows Communication Foundation. I've included a link to the forum where you can ask your question.
http://social.msdn.Microsoft.com/forums/en-us/WCF/threadsSincerely,
Marilyn
-
Why the mouse is hovered over the taskbar only display the date sometimes?
As right now while I am on this site when I move my mouse over the taskbar, the date does not appear. But most of the time this feature works exactly as it should.
So why it still does not work?
And does anyone get off these darn malware or reinstall Windows roads! I sure Ain 'goin' t' we. Just read my about me.
Thanks John. I'm going a few more mindful of that and try to give some useful information. At the moment it displays the date very well when hovered, but I realized that this problem seems to come and go.
-
How can I print my photos displaying the date and time stamp
I have pictures in a legal context but do not understand how to print them displaying the date and time stamp. The timbre of the date and time are necessary for me to present my case exactly. Can someone tell me how to print with these marks.
Thank you
The following instructions will prepare photos
with the EXIF Date/time stamp then you can print
them.FastStone Image Viewer freeware can add
EXIF Date/time in the face of your photos in a batch.(FWIW... it's always a good idea to create a system)
Restore point before installing software or updates)FastStone Image Viewer
http://www.FastStone.org/FSViewerDetail.htm
(Windows XP / Vista / 7)I suggest that you create a new folder and add
copies of your photos for experimental purposes.
If you are unhappy with the result your originals
will be intact.After FastStone is downloaded and installed...
Open the program and go...Tools / open the Batch Conversion / tab Batch convert...
Check the box... Use of advanced options...
Advanced Options button / tab text.
Check the box... Add text...(You will need to experiment with the position and the police
size and color to get the desired result.)
(the text size will need to be adjusted according to the)
the size of the photos)Open the window drop... "Insert a Variable."
choose... EXIF Date Time / Date and time...
(in the white field you should see ($H1)
Left click... OkOn the Batch tab convert... in the left field...
Left click the square button "select the Source folder.
Find and select the photos you want to
Add.Left, click on the Add button to move the files to
the right field.Choose an output Format...
Choose an output folder...
Click on the button convert...
It's much easier to do than to explain then
give it a try before say you "Good Grief... it's too
a lot of work. -
display the date in the task bar
I bought a new netbook for my wife and see that the date is now displayed in the bar tasks over time. How to display the date like this on my laptop more old?
Hi Dlthrasher,
· Did you do changes on the computer before the show?
Follow the suggestions below for a possible solution:
Method 1: I suggest you to check the date and time settings in control Panel. You can see the article for more information:
Change the display of dates, times, currencies, and measures
Method 2: Try the SFC (System File Checker) scan on the computer.
How to use the System File Checker tool to fix the system files missing or corrupted on Windows Vista or Windows 7
http://support.Microsoft.com/kb/929833
Let us know if you need more assistance.
-
My user folder displays the data of 30 GB. Actual data are only 2 GB. I want to wipe my drive C of hidden data. How can I get the details of 30 GB of data shown in the properties of the folder.
Hello
This free program allows you to see what is taking place.
http://www.Jam-software.com/treesize_free/
Here's how to understand Treesize Screenshots:
http://www.Jam-software.com/treesize_free/screenshots.shtml
____________________________________
Also check how much space system restore uses:
http://Windows.Microsoft.com/en-us/Windows7/how-much-disk-space-does-System-Restore-require
_____________________________________
You can clean your hard drive using these two methods.
"Delete files using Disk Cleanup"
Using the free CCleaner program:
http://www.Piriform.com/CCleaner
In NO case use the registry cleaning Option in CCleaner
_____________________________________
Download, install, update and scan your system with the free version of Malwarebytes AntiMalware:
http://www.Malwarebytes.org/products/malwarebytes_free
And Norton Backup, if you are using Norton, can do strange things with filling of hard drive space.
See you soon.
-
Help with a 3rd party on my Web site widget (does not display the dates of concerts)
Hello world!
I use a Bandsintown widget to display the dates of the show on my site, but lately it does not show the text, the widget shows but no text, you can click which means that the widget works but it does not show the text. I contacted Bandsintown support and they told me to change the CSS, but honestly I don't know what they are talking about.
Here's a link to my site, if someone wants to help
Hey Urbano... I finally got the Bandsintown html code to work properly in Adobe Muse. I created a new white master with no background, images, etc. and applied to a new, blank page. Then I pasted the original HTML... with no changes and no additional graphics on the page. It worked... I could see all the information of the tour. Then, one by one, I added additional elements to the master page... as image background, menu, logo, etc. I kept it check each time I added an item until my page has been done. It worked. You can see it here: shellyphelps.com/tour. Why does it work? I have no idea, but I'm guessing it has something to do with the fact that "by default, the widget uses the styles of the page, in that it is included". I'm not a coder either... just determined to understand! LOL I hope it works for you.
Thank you
Shelly
-
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
-
PivotTable ' display the data as "percentage of accuracy
Hello
I would like to know if there is a way to configure the PivotTable ' display the data sub - percentage of ' precision.
ATM, I have reports using SR types where one of those who are much bigger than others... Thus, when its generated report, it returns something like:
TYPE A: 99%
TYPE B: 0%
TYPE C: 0%
TYPE D: 0%
How can I view other correct value types? Something like number of decimals...
PS: as criteria in this report, I changed my data Format 'Number', ' less:-123 "to 15 decimal places.»
Thank you
Ramon902360 wrote:
HelloI would like to know if there is a way to configure the PivotTable ' display the data sub - percentage of ' precision.
ATM, I have reports using SR types where one of those who are much bigger than others... Thus, when its generated report, it returns something like:
TYPE A: 99%
TYPE B: 0%
TYPE C: 0%
TYPE D: 0%How can I view other correct value types? Something like number of decimals...
PS: as criteria in this report, I changed my data Format 'Number', ' less:-123 "to 15 decimal places.»
Thank you
RamonWell Yes. Can do. Read this link:
http://shivabizint.WordPress.com/2008/09/14/changing-the-precession-of-percent-of-columns-in-pivot-table-of-OBIEE/
-
I need a SQL to display the Mon - Sun in a week when enter a date. If I give 24 March 2011 "I want Mon - Sun displayed dates IE from March 21, 2011 to March 27, 2011."
Even if this question is asked a lot times I decided to post this time.
Next time if you could search the forum it will be very much appreciated.
SQL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for 64-bit Windows: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production SQL> alter session set nls_Date_Format = 'DD-MON-YYYY'; Session altered. SQL> with t 2 as 3 ( 4 select next_day(to_date('&Enter_Date','dd.mm.yyyy') - 7, 'SUN') start_date from dual 5 ) 6 select start_date + level from t 7 connect by level <= 7 8 / Enter value for enter_date: 24.03.2011 old 4: select next_day(to_date('&Enter_Date','dd.mm.yyyy') - 7, 'SUN') start_date from dual new 4: select next_day(to_date('24.03.2011','dd.mm.yyyy') - 7, 'SUN') start_date from dual START_DATE+ ----------- 21-MAR-2011 22-MAR-2011 23-MAR-2011 24-MAR-2011 25-MAR-2011 26-MAR-2011 27-MAR-2011 7 rows selected.
Thank you
REDA
Maybe you are looking for
-
How to get back my AT &; T Yahoo Home Page and the toolbar?
I am a senior with little computer knowledge. I can't deal with the changes to my home page because I don't have the knowledge/skills to undo the changes that your program installed.AT & T is my Internet service provider. Firefox is my browser. Right
-
How to set up Wi - Fi connection?
I set up a wireless lan network at home, my laptop has detected the wireless LAN and he says it's connected, but I can't access the internet, it is constantly the access denied, can someone tell me how to configure my phone to have access to the inte
-
Using firefox - verizon yahoo mail Anyone know how I can fix this?
-
I was wondering if there are plans for microsoft to come out with a service pack 4 for Windows xp? Maybe add a few cool gadgets for us guys of the die hard xp?
-
typtype the usb cable usb cord
What type of power cord usb for photosmart d110