Max date in each day
Hi
How can I to get the max Date in each day in data below , I must to do in unique query
select to_date('1/6/2010 06:29:04','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:29:04','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:28:03','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:27:58','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:27:57','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:27:57','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:27:52','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:27:45','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:12:48','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:12:42','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('1/6/2010 06:09:53','dd/mm/yyyy hh24:mi:ss') DATA from dual UNION
select to_date('31/05/2010 06:39:04','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:38:04','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:37:03','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:37:02','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:36:57','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:36:56','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:27:52','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:27:45','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:12:48','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:12:42','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA from dual union
select to_date('31/05/2010 06:09:53','dd/mm/yyyy hh24:mi:ss') DATA from dual
ORDER BY 1 DESCUsing Oracle 9.2.02
TIA
Also possible if you need all the days bettween your first and last day.
with tab as (
select to_date('1/6/2010 06:29:04','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:29:04','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:28:03','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:27:58','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:27:57','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:27:57','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:27:52','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:27:45','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:12:48','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:12:42','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('1/6/2010 06:09:53','dd/mm/yyyy hh24:mi:ss') DATA from dual UNION all
select to_date('31/05/2010 06:39:04','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:38:04','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:37:03','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:37:02','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:36:57','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:36:56','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:27:52','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:27:45','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:12:48','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:12:43','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:12:42','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:12:41','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('31/05/2010 06:09:53','dd/mm/yyyy hh24:mi:ss') DATA from dual union all
select to_date('28/05/2010 02:09:53','dd/mm/yyyy hh24:mi:ss') DATA from dual
,maxmin as (select trunc(min(data)) mindat, trunc(max(data)) maxdat, trunc(max(data))-trunc(min(data))+1 no_of_days from tab)
,days as (select rownum + (select mm2.mindat from maxmin mm2) - 1 dy
from all_objects ao
where rownum <= (select mm1.no_of_days from maxmin mm1))
select d.dy, (select max(data) from tab where trunc(data) = d.dy) max_time
from days d
dy max_time
28.05.10 00:00:00 28.05.10 02:09:53
29.05.10 00:00:00
30.05.10 00:00:00
31.05.10 00:00:00 31.05.10 06:39:04
01.06.10 00:00:00 01.06.10 06:29:04
Similar Messages
-
MIN and MAX date for each range
Hi folks,
I´ve got the following problem:
Given a table
create table t as select 'AT' OM_LANDTEXT, '12345' OM,
to_date('01-JAN-2004', 'DD-MON-YYYY') datum from dual
union
select 'AT' OM, '12345' OM_LANDTEXT,
to_date('02-JAN-2004', 'DD-MON-YYYY') datum from dual
union
select 'AT' OM, '12345' OM_LANDTEXT,
to_date('03-JAN-2004', 'DD-MON-YYYY') datum from dual
union
select 'AT' OM, '12345' OM_LANDTEXT,
to_date('05-JAN-2004', 'DD-MON-YYYY') datum from dual
union
select 'AT' OM, '12345' OM_LANDTEXT,
to_date('06-JAN-2004', 'DD-MON-YYYY') datum from dual
union
select 'AT' OM, '12345' OM_LANDTEXT,
to_date('01-FEB-2004', 'DD-MON-YYYY') datum from dual
union
select 'AT' OM, '12345' OM_LANDTEXT,
to_date('02-FEB-2004', 'DD-MON-YYYY') datum from dual
union
select 'AT' OM, '12345' OM_LANDTEXT,
to_date('03-FEB-2004', 'DD-MON-YYYY') datum from dual;
SQL> select * from t;
OM OM DATUM
AT 12345 01-JAN-04
AT 12345 02-JAN-04
AT 12345 03-JAN-04
AT 12345 05-JAN-04
AT 12345 06-JAN-04
AT 12345 01-FEB-04
AT 12345 02-FEB-04
AT 12345 03-FEB-04
8 rows selected.I need to have the first and last date for om and om_landtext for each date range (where "date range" means a set of consecutive dates with no gaps).
So the ouput should be
OM OM_LANDTEXT DATVON DATBIS
AT 12345 01-JAN-04 03-JAN-04
AT 12345 05-JAN-04 06-JAN-04
AT 12345 01-FEB-04 03-FEB-04Any ideas...?
Thanks for your help!
Best regards,
Gerd
Message was edited by: Gerd
Sorry, I forgot to mention this should be done in pure SQL if possible.
[email protected]This is the plodding, methodical approach I've always taken, which leaves me somewhat in awe of Rod West's solution.
SELECT om_landtext,
om,
MIN(datum) AS min_datum,
MAX(datum) AS max_datum
FROM (
SELECT om_landtext,
om,
datum,
prev_datum,
COUNT(
CASE
WHEN prev_datum IS NULL THEN 'x'
WHEN prev_datum != datum-1 THEN 'x'
ELSE NULL
END
) OVER (PARTITION BY om_landtext, om ORDER BY datum) AS grp
FROM (
SELECT om_landtext,
om,
datum,
LAG(datum) OVER (PARTITION BY om_landtext, om ORDER BY datum) AS prev_datum
FROM t
GROUP BY
om_landtext,
om,
grp;null -
Using pl/sql function for each day between two dates.
Hi,
create TABLE EMP(
ID_EMP NUMBER,
DT_FROM DATE,
DT_TO DATE,
CREATE_DATE DATE);
into EMP(ID_EMP, DT_FROM, DT_TO, CREATE_DATE)
Values(100, TO_DATE('07/01/2008 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/30/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),TO_DATE('05/08/2009 14:11:21', 'MM/DD/YYYY HH24:MI:SS'));
I have a function called elig_pay_dates(date p_date), which returns the code for person payment eligibility for a particular date. For paid dates it's 'P' and for unpaid dates it's 'N'.
How can I check this function between two dates for each day. Example : 07/01/2008 to 04/30/2010.
By using this function with select I needs to display the dates when there is a change in status.
I am expecting data in following manner from above logic(this is example):
07/01/2008 --- 07/01/2009 ---'P'
07/02/2009 -- 07/25/2009 ----'N'
07/26/2009 -- 01/01/2010 ---'P'
01/02/2010 -- 01/13/2010 --'N'
01/14/2010 -- 01/18/2010 --'P'
01/19/2010 -- 04/30/2010 -- 'N'
I thought of looping for each day date but that seems to be expensive for online application. Is there any way that I can achieve this requirement with sql query ?
Thanks for your help,Certainly not the best way to code the requirement, but it does achieve the result you are looking for in a fairly quick time
create or replace
function test_ret_paid_unpaid (p_date in date)
return varchar2
is
v_ret varchar2(1);
begin
if ( (p_date between to_date('07/02/2009', 'MM/DD/YYYY') and to_date('07/25/2009', 'MM/DD/YYYY') ) or
(p_date between to_date('01/02/2010', 'MM/DD/YYYY') and to_date('01/13/2010', 'MM/DD/YYYY') ) or
(p_date between to_date('01/19/2010', 'MM/DD/YYYY') and to_date('04/30/2010', 'MM/DD/YYYY') )
then v_ret := 'N';
else
v_ret := 'Y';
end if;
return v_ret;
end;
Wrote file afiedt.buf
1 with get_paid_unpaid as
2 (
3 select dt_from start_date, dt_to end_date, dt_from + level - 1 curr_date, test_ret_paid_unpaid(dt_from + level - 1) paid_unpaid,
4 row_number() over (order by dt_from + level - 1) rn_start,
5 row_number() over (order by dt_from + level - 1 desc) rn_end
6 from test_emp
7 connect by level <= dt_to - dt_from + 1
8 ),
9 get_stop_date as
10 (
11 select start_date init_date, end_date, curr_date, paid_unpaid,
12 case when paid_unpaid != lag(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
13 then curr_date
14 else null
15 end start_date,
16 case when paid_unpaid != lead(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
17 then curr_date
18 else null
19 end stop_date
20 from get_paid_unpaid
21 )
22 select period, paid_unpaid
23 from (
24 select init_date, curr_date, start_date, end_date, stop_date,
25 case when paid_unpaid = lead(paid_unpaid) over (order by curr_date)
26 then nvl(start_date, init_date) || ' - ' || lead(stop_date, 1, end_date) over (order by curr_date)
27 else null
28 end period,
29 paid_unpaid
30 from get_stop_date
31 where stop_date is not null or start_date is not null
32 )
33* where period is not null
12:06:10 SQL> /
PERIOD PAID_UNPAID
01-JUL-08 - 01-JUL-09 Y
02-JUL-09 - 25-JUL-09 N
26-JUL-09 - 01-JAN-10 Y
02-JAN-10 - 13-JAN-10 N
14-JAN-10 - 18-JAN-10 Y
19-JAN-10 - 30-APR-10 N
6 rows selected.
Elapsed: 00:00:00.35 -
Selecting max date for specific 'operation' code
I have the following scenario: a history table that keeps track of the 'operation' and the date of the operation. For example, the operation field can have a code of U (for update), C (for closed), O (for re-opened), A (for approved), etc.
The goal of this history table is to keep track of all of the modifications made. Hence, a particular record of interest can have more than one 'U' operation documented, C operation, etc.
How can I choose the max date for each operation.
I was diong the following in my PL/SQL:
BEGIN
SELECT operation_code, o_date, user INTO lv_operation_code, lv_date, lv_user FROM table1 WHERE unique_id = pv_id AND operation_code = U' AND o_date = (SELECT max(o_date) FROM table1 WHERE unique_code = pv_id);
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END;
I then have another begin statement for the 'C' operation, etc.Hi,
OraclePolzovatel wrote:
... I was diong the following in my PL/SQL:
BEGIN
SELECT operation_code, o_date, user INTO lv_operation_code, lv_date, lv_user FROM table1 WHERE unique_id = pv_id AND operation_code = U' AND o_date = (SELECT max(o_date) FROM table1 WHERE unique_code = pv_id);
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END;
I then have another begin statement for the 'C' operation, etc.Are you sure that's what you're doing? There seem to be errors, such as unmatched quotes.
Instead of doing a single SELECT with something like "operation_code = 'U'" in the WHERE-clause, you could write a cursor with "GROUP BY operation_code". -
How to enter a new Date and Time each day in a Numbers Spreadsheet...
Hi... I have finally decided to move away from Excel and really give Numbers a shot... I have an application where each day I first enter the current date and time into a particular cell of a new row and then I enter some data in cells adjacent (in the same row) as that entered date-time. Then the next day I want to again enter the (new) current date and time and add more data next to that new date-time and so forth day after day... You can't use something as simple as =NOW() because then everyday, ALL of the date-times would change to the current time... Nope, now what I want... I just want to be able to EASILY and QUICKLY enter the current date-time value in one call and then have that specific value stay there forever... In Excel, this is accomplished with the keyboard shortcuts of
<cntl> followed by a semicolon (;) for the date
then enter a single space (for separation of date versus time) followed last by
<command> followed again by a semicolon...
So all together that is,
<cntl><;><sp><command><;>
and that puts something like
4/10/2010 9:49:00 AM
in a single cell...
That's what I now want to be able to do in Numbers...
How do I do that??? Do I use the menubar item "Insert Date and Time" and if so, how exactly do I get the current time to show up in the chosen cell??? With formatting??? Is there a keyboard shortcut method like the one I mentioned that works for Excel?? I've perused the manual and though I found lots on date-time, I didn't see how to do specifically what I want to do... I likely just missed it as surely it must be easy to do...
Any feedback would be much appreciated... thanks... bob...Badunit wrote:
The result of running that script is "UI Enabled = TRUE".
I have cells named by the header values.
This may be the problem.
The script is an old one which deciphered only the letter+digit cell references.
Here is a new version which works with every kind of cell reference.
--[SCRIPT insertDateTime]
Enregistrer le script en tant que Script : insertDateTime.scpt
déplacer l'application créée dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
Placez le curseur dans la cellule qui doit recevoir la date_heure
menu Scripts > Numbers > insertDateTime
La cellule pointée reçoit la date_heure.
L'aide du Finder explique:
L'Utilitaire AppleScript permet d'activer le Menu des scripts :
Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case "Afficher le menu des scripts dans la barre de menus".
+++++++
Save the script as a Script : insertDateTime.scpt
Move the newly created application into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
Put the cursor in the cell which must receive the date_time.
menu Scripts > Numbers > insertDateTime
The pointed cell receives the current date_time.
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
Yvan KOENIG (VALLAURIS, France)
2009/03/01
2010/04/11 is now able to treat every kind of cell references
property theApp : "Numbers"
--=====
on run
set {dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
my doYourDuty(colNum1, rowNum1, tName, sName, dName)
end run
--=====
on doYourDuty(c, r, t, s, d) (*
c = columnIndex
r = rowIndex
t = table's name
s = sheet's name
d = document's name *)
local cdt
set cdt to my cleanThisDate(current date) (* the new date_time as a clean date_time *)
tell application "Numbers" to tell document d to tell sheet s to tell table t
set value of cell r of column c to cdt as text
end tell -- application …
end doYourDuty
--=====
on cleanThisDate(dt)
(* ugly code but once I got date_time with milliseconds so if necessary, I drop them *)
local l
set l to my decoupe(dt as text, ":")
if (count of l) > 3 then set dt to date (my recolle(items 1 thru 3 of l, ":"))
return dt
end cleanThisDate
--=====
on getSelParams()
local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
set {d_Name, s_Name, t_Name, r_Name} to my getSelection()
if r_Name is missing value then
if my parleAnglais() then
error "No selected cells"
else
error "Il n'y a pas de cellule sélectionnée !"
end if
end if
set two_Names to my decoupe(r_Name, ":")
set {row_Num1, col_Num1} to my decipher(item 1 of two_Names, d_Name, s_Name, t_Name)
if item 2 of two_Names = item 1 of two_Names then
set {row_Num2, col_Num2} to {row_Num1, col_Num1}
else
set {row_Num2, col_Num2} to my decipher(item 2 of two_Names, d_Name, s_Name, t_Name)
end if
return {d_Name, s_Name, t_Name, r_Name, row_Num1, col_Num1, row_Num2, col_Num2}
end getSelParams
--=====
set {rowNumber, columnNumber} to my decipher(cellRef,docName,sheetName,tableName)
apply to named row or named column !
on decipher(n, d, s, t)
tell application "Numbers" to tell document d to tell sheet s to tell table t to return {address of row of cell n, address of column of cell n}
end decipher
--=====
set { d_Name, s_Name, t_Name, r_Name} to my getSelection()
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
tell application "Numbers" to tell document 1
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
try
(selection range of table y) as text
on error errMsg number errNum
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
return {theDoc, theSheet, theTable, theRange}
end try
end repeat -- y
end if -- x>0
end tell -- sheet
end repeat -- i
end tell -- document
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
on parleAnglais()
local z
try
tell application theApp to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--[/SCRIPT]
It's available on my idisk :
<http://public.me.com/koenigyvan>
Download :
For_iWork:iWork '09:for_Numbers09:insertDateTime.zip
Yvan KOENIG (VALLAURIS, France) dimanche 11 avril 2010 14:16:41 -
How to create a folder with date each day?
I've not used Automator, just once to "create" a workflow to create a new folder with a name; but what I want is this:
Each morning at 12:01 am, a new folder to be created with the correct date as the name of the folder.
So for tomorrow, Sunday 23 Nov 2008 at 12:01, I'd suddenly have a folder on my Hard Drive that would have the date like 23 Nov 2008 or 11/23/2008 or 23-11-2008 or similar.
Then at the end of a week I'd have 7 of these; - but I can manually trash them-- I want to create these on my HD since I backup via SuperDuper! each morning (automatically) at 3:35 am (incremental backup to an external La Cie HD) and I want to know if was done, so by having a folder with the date on it I can open the external HD and if I see that that folder with the recent date is there, then I'm confident the BackUp was run.
I have been able to create a workflow to create a folder in Automator, but not sure how to:
1. Have the folder created automatically each day at 12:01
2. How to have the folder label be the date
Thanks for any comments or certainly any other work-around or other way to do this or similar.
Regards, SteveOpen the AppleScript Editor. Copy the following into it:
set dt to date string of (current date)
set mth to word 2 of dt
set dy to word 3 of dt
set yr to word 4 of dt
set dtt to mth & " " & dy & " " & yr
tell application "Finder"
make new folder at alias "Macintosh HD:Users:username:Desktop:" with properties {name:dtt}
end tell
Amend the path with your Hard Disk name and username. Save as an application to anywhere suitable.
In iCal, set up an event with a daily repeat and an alarm at the time you want it: under 'Alarm' choose 'Open file': then in the next menu which will appear change from 'iCal' to 'Other' and navigate to your script. Enter the date and time.
Your folder will be created as required: iCal does not need to be running. This script gives the folder name as, for example, 'November 22 2008', but it's easy to amend the script if you want something a bit different - for example:
property zro : ""
set yr to year of (current date) as string
set dy to day of (current date)
set mt to month of (current date)
set dyy to dy as string
set nmm to the number of items in dyy
if nmm is 1 then
set zro to 0
end if
if mt is January then
set mth to "01"
else if mt is February then
set mth to "02"
else if mt is March then
set mth to "03"
else if mt is April then
set mth to "04"
else if mt is May then
set mth to "05"
else if mt is June then
set mth to "06"
else if mt is July then
set mth to "07"
else if mt is August then
set mth to "08"
else if mt is September then
set mth to "09"
else if mt is October then
set mth to "10"
else if mt is November then
set mth to "11"
else if mt is December then
set mth to "12"
end if
set dtt to mth & "-" & zro & dy & "-" & yr as string
tell application "Finder"
make new folder at alias "iBook HD:Users:roger:Desktop:" with properties {name:dtt}
end tell
This gives the folder name as, for example, 11-22-2008. (The days will have leading zeros, if you don't want these just remove the references to 'zro'.) -
Start routine for insert a record by each day in a range of dates
Hi all,
I need create a start routine for insert 1 record by each day in a range of dates:
example:
Actual.
DATE_I DATE_F TIME_I TIME_F TIME_minutes
04/04/2008 05/04/2008 13:40:00 23:00:00 2000
Result:
DATE_I DATE_F TIME_I TIME_F TIME_minutes
04/04/2008 04/04/2008 13:40:00 24:00:00 X
05/04/2008 05/04/2008 00:00:00 23:00:00 Y
I thanks any help.
regards.
Alberto.Hi Alberto,
What I understood from your requirement is that you want to split the record into 2 since you have 2 dates coming from the source.
In the transformations you will have to create new rule group one for each of the dates.
You can create the new rule group by clicking on the 'Rule Group' button and then clicking on the 'New Rule Group'.
In the newly created rule groups take care to distribute data for each date separately.
Hope it is clear.
All the best...
Regards,
Krishna -
Count of Active Customers each day between two dates
Hi Folks
I have a table as shown in the screenshot. The id column is a customer id, and the activated and cancelled date columns represent when a customer signed-up or cancelled their subscription. I want to count how many customers were active each day (from
the earliest activation date to the current date, note non-cancelled customers have a cancelled date of 2099-01-01). Any suggestions on how to do this?
Regards
Steve>> I have a table as shown in the screenshot. <<
Where is the DDL? Does your boss make you program from screenshots? So you have to type in the data by hand? And guess at keys and constraints? Wow! That is an awful place to work!
>> The “id” column is a “customer_id”, <<
Why did you not call it that? Being rude is fine, but being vague is bad. :( Here is my guess.
CREATE TABLE Customers
(customer_id CHAR(5) NOT NULL PRIMARY KEY, --- wild guess !
activation_date DATE NOT NULL,
cancellation_date DATE,
CHECK (activation_date < cancellation_date), --- second wild guess!
>> I want to count how many customers were active each day (from the earliest activation date to the current date. Note non-cancellation customers have a cancellation date of 2099-01-01). <<
You will need a Calendar table (Google it) and a book on basic data modeling. We use a NULL for missing data in SQL and RDBMS. This is how we implement the ISO half-open temporal model. We also use DATE for dates now. There is no need to use the old Sybase/UNIX
datetime with '00:00:00.000' and in fact it is awful coding today.
WITH X (customer_id, cal_date)
AS
(SELECT A.customer_id, C.cal_date
FROM Customers AS A, -– for active
Calender AS C
WHERE C.cal_date
BETWEEN MIN(A.activation_date) OVER()
AND (COALESCE(cancellation_date,
CAST (CURRENT_TIMESTAMP AS DATE))
SELECT COUNT(X.customer_id) AS active_customer_cnt
FROM X
GROUP BY cal_date;
Untested due to lack of sample data.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Abap query : retrieve max date for the each unique material
Hi
I am facing problem formulating an ABAP query to retrieve records of table1 - material , table2 - doc no , table2 - doc date.
I need records having maximum doc date for each material.
I have used inner join on doc no on both tables.
Please help.
Thanks in advance
Ash RHello Mr.Ravi,
I have used descending for "date" but i want single record for each material.
it is like this:
SELECT AMATNR EMBLNR E~BUDAT
INTO CORRESPONDING FIELDS OF TABLE IT_FSN
FROM MSEG AS A INNER JOIN MKPF AS E ON EMBLNR = AMBLNR
UP TO 1 ROWS
WHERE AWERKS = P_PLANT AND ABWART IN S_MTYPE AND E~BUDAT IN S_DATE
GROUP BY AMATNR EBUDAT E~MBLNR
ORDER BY E~BUDAT DESCENDING.
I'm not able to get what i'm missing.
please help.
Regards,
Ash R -
Hi
I have a query ,it gives total count of month
select count(*) from w_srvreq_d where status='Closed' and trunc(close_dt)>'01-may-2003' AND trunc(close_dt)<='31-may-2003'
COUNT(*)
82
I want count for each day
ex
date count
1/5/03 1
2/5/03 2
31/5/03 12
Regards
MohanHi
select count(*) from w_srvreq_d where status='Closed' and trunc(close_dt)>'01-may-2003' AND trunc(close_dt)<='31-may-2003'
COUNT(*)
82
My scnerio is want to join w_day_d and w_srvreq_d dimension and populate in to fact table .This below query populate the data in bt_fault_snapshot_f table,But i want count for each day
date count sr_cat_type_cd x_bt_current_queue
1/5/03 1 complaint unspecifie
2/5/03 2 Fault unspecified
SELECT dlr.sr_cat_type_cd,
dlr.x_bt_current_queue,dlr.x_bt_line_of_business ,
day.snapshot_date AS snapshot_date FROM
( SELECT w_day_d.day_dt AS snapshot_date
FROM (SELECT to_date(nvl(max(date_wid),'20030531'),'yyyymmdd')+1
AS snapshot_date
FROM bt_fault_snapshot_f) f ,
w_day_d , (SELECT CASE WHEN to_number(to_char(sysdate,'hh24')) <18 THEN trunc(sysdate - 1)
ELSE trunc(sysdate)
END AS lastdate FROM dual) currdate
WHERE w_day_d.day_dt >= f.snapshot_date
AND w_day_d.day_dt <= currdate.lastdate) day
, ( SELECT DISTINCT sr_cat_type_cd,x_bt_current_queue,x_bt_line_of_business
FROM w_srvreq_d) dlr
Regards
Mrao -
Max date by month in expression builder
Hello
I'd need to create a new logical column and use the expression builder to make this column return only the last day of each month. I know at answers level I can write something like this in the formulas: Max(Date by month). However I can't do that in expression builder as it doesn't like the word 'by'..
Is there a way to get it done?
Thanks in advance!Hello,
The max(date) should work in logical layer. As when you pull in month it automatically groups by month.
thanks,
deep -
Query - weight delivered each day
Hi all.
I'm currently working at a query to calculate the weight delivered each day. My thougt is to first calculate from DLN1 table and then subtract from RDN1 table. Deliveries minus returns.
I can easily create these queries as stand alone queries, but I would need some help combining them into one query. I'm thinking coulmns like this; A = date, B = weight deliveries, C = weight returns, D = B minus C
Any takers?
Thanks and regards.
Runar Wigestrand.Hi!
Check this ....
Declare @FromDate Datetime
Declare @ToDate Datetime
Set @FromDate = (Select min(s0.Docdate) from ODLN S0 where S0.Docdate >='[%0]')
Set @ToDate = (Select max(s1.Docdate) from ODLN S1 where S1.Docdate <='[%1]')
Select
a.Docdate,sum(a.DW) as [Delivery Weight],sum(a.RW) as [Return Weight],
sum(a.DW)-sum(a.RW) as [Total Weight] from (
SELECT T1.[DocDate], SUM(cast(T0.[Weight1] as int)) as DW,0 as RW
FROM DLN1 T0 inner join ODLN T1
on T0.DocEntry = T1.DocEntry
WHERE
T1.DocDate between Convert(Char(10),@FromDate) and Convert(char(10),@ToDate)
Group by T1.[DocDate]
Union all
SELECT T1.[DocDate], 0 as DW,SUM(cast(T0.[Weight1] as int)) as RW
FROM RDN1 T0 inner join ORDN T1
on T0.DocEntry = T1.DocEntry
WHERE
T1.DocDate between Convert(Char(10),@FromDate) and Convert(char(10),@ToDate)
Group by T1.[DocDate] )a
Group By
a.Docdate -
Verizon Max Data Plans are not a deal
I just read about the Olive Branch Verizon has extended to us obstinate unlimited data plan holders.
The Max Data Plans are a weed dressed up to look like an Olive Branch.
I did the math on my unlimited nill vs a Max Bill with Edge phones. Currently I pay $201.75 for two lines + unlimited data.
I have an S4, so I don't need a new phone, but if I did I would go Note 3. My wife has an iPhone 5 64gb, so a 5s 64gb would be a good choice.
After crunching the numbers and entering Edge would go up to 221.68 per month. That's right up not down.
Knowing this, why would I give up unlimited
data?Michael,
I am so tired of reading these Verizon forums, and seeing all these people who have been victimized by losing their unlimited data become Verizon's biggest defenders. Misery truly loves company. I don't care what they say, be it saving a few bucks for losing unlimited data (yet ignoring opportunity costs in keeping unlimited data OR even leveraging the unlimited data in other ways by utilizing "assumption of liability"), or praying for this magical day of July, 2014 when we're all supposed to lose unlimited data (which is complete and utter nonsense, forget speculation.) I thought that Verizon was supposed to be the one providing us a service, and not the other way around...though I suppose the Stockholm Syndrome folks enjoy that, I guess.
Problem is there doesn't appear to be many people who have unlimited data offering information that would help people like us KEEP unlimited data; all it is are these people inundating these forums with misinformation and misery about losing unlimited data.
So I will just tell you what I did to upgrade and hope that points you in the right direction.
Recently, I did use the Device Payment Plan (different from Edge, which sounds like utter garbage) to get a Note 2. 700 divided by 12 plus $24 total. I figured why not; anything to get off this Samsung Droid Charge. Now, I am utilizing the alternate upgrade method, which allows me to upgrade a basic phone in my plan and switch that phone to the line with the Note 2, which I then will give the Note 2 to the wife, who also has an unlimited data plan. I probably should have done this earlier, but I initially thought it'd be too much work. However, after I did the math, even after activation fees and such, I still get a better phone at a better price than if I Device Payment Plan'ed it.
I will let you know how it goes...I have three unlimited data plans that I can do a "transfer only" to get the hot new phones, and I plan on using anyone of them. And despite what some of you Verizon apologists say, I do not lose unlimited data when I transfer an upgrade to another line, which apparently, I can do THREE times...
I am just sick and tired of seeing these people inundate folks with such bad information. Since this is a peer-to-peer forum where Verizon customers help each other, I figure let me help my fellow Verizon customers SAVE their unlimited data and also help lead in the ignoring of these bitter haters who just want other people to be miserable by having you lose your unlimited data plan. -
Select previous max(date) and current max(date) in trigger
Good mroning fellows!
I am trying to develop a row level trigger that inserts data into another table after insert.
Within the trigger I need to calculate a couple of averages based on dates. Therefore I need to select the date of the previously entered record and calculate the days between this last record and the current entry that was just saved.
Is it possible to write it like that in the trigger?
create or replace
TRIGGER borki.set_tageswerte
AFTER INSERT
ON borki.fangzahlen
FOR EACH ROW
-- WHEN (NEW.qb_nr > 0 AND NEW.lrt_fl_id > 0)
DECLARE
old_date date;
latest_date date;
days number;
avergae_amount integer;
BEGIN
old_date := (SELECT max(:old.date_datum)
FROM borki.fangzahlen
WHERE lng_falle = :new.lng_falle
AND int_fallennummer = :new.int_fallennummer
AND lng_schaedling = :new.lng_schaedling);
latest_date := (SELECT max(:new.date_datum)
FROM borki.fangzahlen
WHERE lng_falle = :new.lng_falle
AND int_fallennummer = :new.int_fallennummer
AND lng_schaedling = :new.lng_schaedling);
days := latest_date - old_date;
average_amount := (SELECT CASE
WHEN f.int_volumen > 0 AND f.lng_schaedling = 1 THEN f.int_volumen * 40
WHEN f.int_volumen > 0 AND f.lng_schaedling = 2 THEN f.int_volumen * 550
WHEN f.int_anzahl > 0 THEN f.int_anzahl
END
/ days AS tagesfang
FROM borki.fangzahlen f
WHERE f.lng_falle = :new.lng_falle
AND f.int_fallennummer = :new.int_fallennummer
AND f.lng_schaedling = :new.lng_schaedling
AND days > 0
AND ((f.int_anzahl > 0) OR (f.int_volumen > 0)))
INSERT
INTO fangzahlen_tageswerte
lng_falle, date_datum, int_fallennummer, lng_schaedling, int_volumen, int_anzahl, lng_fangzahlen
VALUES
(SELECT f.lng_falle,
:new.date_datum, :new.int_fallennummer,
:new.lng_schaedling, :new.int_volumen,
:new.int_anzahl - ((y-1)*rec.tagesfang),
:new.objectid
END;thanks for sharing your wisdom mith me! :-)
Sebastian
Edited by: skahlert on 07.04.2010 07:04Hello Tubby!
You're correct!
I'll take the time and show you what I got and what I need!
I am working with an Apex frontend where users enter scientific data for beetle monitoring.
The data entered consists of --> date_datum: date when last trap was emptied
--> int_volumen: the volume of the trap (used to calculate found specimen when int_anzahl is null)
--> int_anzahl: amount of found beetles
--> lng_schaedling: type of beetle (1 or 2)
--> lng_falle:trap number
--> int_fallennummer: sub-trap type (1 or 2)
Background info: Data is entered once or twice a week for each trap. After the data has been entered I need to calculate the mean average depending on the volume or amount.
Therefore I need to sum the colume or amount and divide it by the period of days since the current and last trap removal (that's when the bugs are counted and data is manually entered to the DB). For each day between the last and current trap removal I need to add one record in table fangzahlen_tageswerte (in my proc still called "test" for obvious reasons) that contains the mean average value of found beetles.
I hope I could point out my demand without confusing you!
PS: my problem --> very little background info concerning the entomological monitoring of this beetle type ;-), limited pl/sql skills and the problem that I need to run this procedure for each new record only. If you could show me how to make sure that data is not stored in table fangzahlen_tageswerte multiple times, I could called it directly in APEX.
Otherwise I'd suggest to create a trigger that launches this procedure below and parses the :new.parameters into my pocedure.
Another problem: this might work for insert statements. However, obviously I have to correct the mean values if raw data in table fangzahlen has been updated. Should I call another procedure after update on tbl fangzahlen or integrate that part into the procedure below? Doesn't matter I guess, right?
create or replace
PROCEDURE "PR_FANGZAHLEN_TW_SK" (
pr_falle NUMBER,
pr_fallennummer NUMBER,
pr_schaedling NUMBER
IS
old_date DATE;
diff_days NUMBER (10);
tagesfang NUMBER (12);
y NUMBER (10);
BEGIN
/*Query date of previous record and store it into variable old_date*/
select date_datum into old_date from
(select f.date_datum, row_number() over (order by f.date_datum desc) rn
from borki.fangzahlen f where f.lng_falle = pr_falle
and f.int_fallennummer = pr_fallennummer
and f.lng_schaedling = pr_schaedling) where rn=2;
select max(f.date_datum) - old_date into diff_days from borki.fangzahlen f
where (f.lng_falle = pr_falle)
and (f.int_fallennummer = pr_fallennummer)
and (f.lng_schaedling = pr_schaedling);
FOR rec IN (select sum((case
when f.int_volumen > 0 and f.lng_schaedling = 1
then f.int_volumen * 40
when f.int_volumen > 0 and f.lng_schaedling = 2
then f.int_volumen * 550
when f.int_anzahl > 0
then f.int_anzahl
end
/ (f.date_datum - to_date(old_date))) as tagesfang
from borki.fangzahlen f
where (f.lng_falle = pr_falle)
and (f.int_fallennummer = pr_fallennummer)
and (f.lng_schaedling = pr_schaedling)
and ((f.date_datum - to_date(old_date)) > 0)
and ((f.int_anzahl > 0) or (f.int_volumen > 0)))
LOOP
y := 1;
WHILE y < diff_days + 1
LOOP
/* Insert FANGZAHLEN_TAGESWERTE*/
IF y < diff_days
THEN
INSERT INTO test
(lng_falle, date_datum, int_fallennummer,
lng_schaedling, int_volumen, int_anzahl,
lng_fangzahlen)
SELECT f.lng_falle,
old_date + y, f.int_fallennummer,
f.lng_schaedling, f.int_volumen, rec.tagesfang,
f.objectid
FROM fangzahlen f
WHERE f.lng_falle = pr_falle
AND f.int_fallennummer = pr_fallennummer
AND f.lng_schaedling = pr_schaedling
AND (f.date_datum - old_date) > 0
AND ( (f.int_anzahl > 0)
OR (f.int_volumen > 0) );
END IF;
y := y + 1;
END LOOP;
END LOOP; -- end of cursor
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
-- Consider logging the error and then re-raise
RAISE;
END "PR_FANGZAHLEN_TW_SK";regards,
Seb -
SQL Selecting the first and last entries for each day
Hello SQL experts,
I hope you can help with this.. I have a table (could have 1M or more rows in it) see structure below. I am looking to get the first and last date/times for each employee for each day. I also need the location GUID for the first read.
EmployeeGUID (uniqueidentifier datatype)
LocationGUID (uniqueidentifier datatype)
DateTime (DateTime datatype)
12345678-0000-0000-0000-000000000000
11111111-0000-0000-0000-000000000000
04/12/2014 07:00:01
12345678-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/12/2014 10:40:05
12345678-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/12/2014 17:04:02
44422222-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/14/2014 08:00:00
44422222-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/14/2014 14:00:03
44422222-0000-0000-0000-000000000000
33333333-0000-0000-0000-000000000000
04/15/2014 07:49:00
44422222-0000-0000-0000-000000000000
11111111-0000-0000-0000-000000000000
04/15/2014 09:00:01
This would be the ideal output (I can do without the TotalTimeInHours):
EmployeeGUID (uniqueidentifier datatype)
LocationGUID (uniqueidentifier datatype)
FirstRead (DateTime datatype)
LastRead (DateTime datatype)
TotalTimeInHours
12345678-0000-0000-0000-000000000000
11111111-0000-0000-0000-000000000000
04/12/2014 07:00:01
04/12/2014 17:04:02
Total in hours between the first and last read.
44422222-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/14/2014 08:00:00
04/14/2014 14:00:03
44422222-0000-0000-0000-000000000000
33333333-0000-0000-0000-000000000000
04/15/2014 07:49:00
04/15/2014 09:00:01
I would post what I have tried so far but I have been trying many different types of queries over the last few days. In short I need the employees first and last reads for each date. They could have many entries per date or just 1. I am certain that this
is a trivial thing for a SQL expert but not trivial for me :).
Thank you in advance!Thank you!
This is almost what I need. The LocationGUID has to be included in the output. When I include it, I have to put it in the Group By clause. When I do that the reads are based on the LocationGUID (see below).
** I added a few more data entries and included the LocationGUID in the output.
***** SQL ***********
CREATE TABLE test( EmployeeGUID uniqueidentifier, LocationGUID uniqueidentifier, DateTimeCol DateTime )Insert into test values
('12345678-0000-0000-0000-000000000000','11111111-0000-0000-0000-000000000000','04/12/2014 07:00:01')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 10:40:05')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 17:04:02')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 19:00:00')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/14/2014 08:00:00')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/14/2014 14:04:03')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/15/2014 07:49:00')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/15/2014 09:00:01')
,('12345678-0000-0000-0000-000000000000','11111111-0000-0000-0000-000000000000','04/13/2014 10:40:05')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/13/2014 17:04:02')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/13/2014 19:00:00')
;with mycte as (
SELECT *, row_number() OVER(partition by EmployeeGUID, Cast(DateTimeCol as date) Order by DateTimeCol) rnASC,
row_number() OVER (partition by EmployeeGUID, Cast(DateTimeCol as date) Order by DateTimeCol DESC) rnDESC
FROM test)
Select EmployeeGUID ,Cast(DateTimeCol as date) dt,LocationGUID,
Max(Case when rnASC=1 Then DateTimeCol End) minDateTimeCol
,Max(Case when rnDESC=1 Then DateTimeCol End ) maxDateTimeCol
,Datediff(minute, Max(Case when rnASC=1 Then DateTimeCol End) ,Max(Case when rnDESC=1 Then DateTimeCol End ) )/60.0 TotalTimeInHours
from mycte
Group by EmployeeGUID, LocationGUID,Cast(DateTimeCol as date)
Order by dt,EmployeeGUID
drop TABLE test
**** OUTPUT **********
EmployeeGUID
dt
LocationGUID
minDateTimeCol
maxDateTimeCol
TotalTimeInHours
12345678-0000-0000-0000-000000000000
2014-04-12
11111111-0000-0000-0000-000000000000
2014-04-12 07:00:01.000
NULL
NULL
12345678-0000-0000-0000-000000000000
2014-04-12
22222222-0000-0000-0000-000000000000
NULL
2014-04-12 19:00:00.000
NULL
12345678-0000-0000-0000-000000000000
2014-04-13
11111111-0000-0000-0000-000000000000
2014-04-13 10:40:05.000
NULL
NULL
12345678-0000-0000-0000-000000000000
2014-04-13
22222222-0000-0000-0000-000000000000
NULL
2014-04-13 19:00:00.000
NULL
44422222-0000-0000-0000-000000000000
2014-04-14
22222222-0000-0000-0000-000000000000
2014-04-14 08:00:00.000
2014-04-14 14:04:03.000
6.066666
Maybe you are looking for
-
I tries to backed up and storage on iCloud but its just shows down below "Estimating time remaining" but theres no time remaining !!! And i connect to the Wifi already and i buy a storage capacity !!! But its not backing so what should i do in that c
-
Windows 8 Consumer Preview 32-bit not installing with Disk Utility
I have a late-2011 13" MacBook Pro (Mac OS X 10.7.4). I downloaded the Windows 8 32-bit Consumer Preview ISO from the Microsoft official website (so there is nothing illegal there) and I am trying to burn it to a Maxell 4.7GB (up to 16x) DVD-R using
-
Workflow for vendor down payment request
hi All, i need to develop a workflow for vendor down payment request as there is no standard workflow available. But not able to find any business object for it. Is there any standard business object available for it? If no what are the steps that i
-
Tomcat 5.0.28 Crashing - Unexpected Error detected HotSpot Virtual Machine
# An unexpected error has been detected by HotSpot Virtual Machine: # Internal Error (4A41564123414C4C530E4350500018), pid=2872, tid=2884 # Java VM: Java HotSpot(TM) Server VM (1.5.0_05-b05 mixed mode) --------------- T H R E A D --------------- Curr
-
Lightroom Vs. Aperture - mini shootout
As seen in my earlier thread, I've been playing with the 30 day trial of Lightroom trying to decide whether that tool is a better fit for my needs then Aperture. While I've only spent a few hours with this on a small project I think I've been able to