Get min and max
Thanks in advance for help
I have a query as below
SELECT FI.TCOL1 ,FI.TIPO,FI.TCOL2,COUNT(*) NUM,
SUM(FI.TCOL3) SUM_IPBFA,SUM(FI.TCOL4), MIN(FI.COL5) DA_NUM,MAX(FI.COL6) A_NUM
FROM DBTABLE FI
WHERE TDATA between DATABEG and DATAEND
GROUP BY FI.TCOL1 ,TIPO_A,TCOL2
ORDER BY 1,3 How get MIN e MAX grouped only for FI.TCOL1?
e.g
SELECT FI.TCOL1, MIN(FI.COL5) DA_NUM,MAX(FI.COL6) A_NUM
FROM DBTABLE FI
WHERE TDATA between DATABEG and DATAEND
GROUP BY FI.TCOL1 ,TIPO_A,TCOL2
ORDER BY 1,3Thanks
it will be better if you can post some sample data and output to work on and to get a better understanding of your requirements.
you might want to try this but not sure if this will give you the result you needed:
Select f1.tcol1,
f1.da_num,
f2.a_num
From (SELECT FI.TCOL1,
MIN(FI.COL5) DA_NUM
FROM DBTABLE FI
WHERE FI.TDATA between DATABEG and DATAEND
GROUP BY FI.TCOL1) F1,
(SELECT FI.TCOL1,
MAX(FI.COL6) A_NUM
FROM DBTABLE FI
WHERE FI.TDATA between DATABEG and DATAEND
GROUP BY FI.TCOL1) F2
Where f1.tcol1 = f2.tcol2
Order by 1,2,3
Similar Messages
-
Get min and max for a column from table with 24 million rows.
What is the best way to re-write the following query in a procedure for the table which has around 24 million rows?
SELECT MIN(ft_src_ref_id), MAX(ft_src_ref_id )
INTO gn_Min_ID, gn_Max_ID
from UI_PURGE_FT;
Thanks
Edited by: tcode on Jun 21, 2012 12:31 PMWhich of the following plan is better, can you please breifly explain?
Also I need to gather statics to know recursive calls , db block gets ,consistent gets etc. etc. how can I get that?
Thanks
1.
Execution Plan
Plan hash value: 3702745568
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 6 | 13991 (2)| 00:02:48 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
| 2 | INDEX FAST FULL SCAN | UI_PURGE_FT_PK | 23M| 136M| 13991 (2)| 00:02:48 |
2.
Execution Plan
Plan hash value: 1974183109
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | | 2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
| 2 | INDEX FULL SCAN (MIN/MAX)| UI_PURGE_FT_PK | 23M| 136M| 2 (0)| 00:00:01 |
| 3 | SORT AGGREGATE | | 1 | 6 | | |
| 4 | INDEX FULL SCAN (MIN/MAX)| UI_PURGE_FT_PK | 23M| 136M| 2 (0)| 00:00:01 |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------- -
I shutdown Zone Alarm, and deleted the contents of the file, which contained the "exe" file, then reinstalled Firefox version 5.0. I still get the XUL Runner error message about incompatibility of Version 5.0 with min and max 5.0.1. What next?
The updater wasn't able to update all the files and some were left as older versions.<br />
You need to do a clean reinstall.
Download a fresh Firefox copy and save the file to the desktop.
* Firefox 5.0.x: http://www.mozilla.com/en-US/firefox/all.html
* Uninstall your current Firefox version.
* Do not remove personal data when you uninstall the current version.
Remove the Firefox program folder before installing that newly downloaded copy of the Firefox installer.
* It is important to delete the Firefox program folder to remove all the files and make sure that there are no problems with files that were leftover after uninstalling.
Your bookmarks and other profile data are stored elsewhere in the Firefox Profile Folder and won't be affected by a reinstall, but make sure that you do not select to remove personal data if you uninstall Firefox.
* http://kb.mozillazine.org/Profile_folder_-_Firefox
* http://kb.mozillazine.org/Profile_backup -
Min and MAx Value in a SELECT Statement
Hi,
I have a scenario where I am Selecting the values BETWEEN MIN and MAX values:
SELECT * FROM ABC WHERE CODE BETWEEN MIN(CODE) AND MAX(CODE)
ITS GETTING Error as:ORA-00934: group function is not allowed here
Any help will be needful for me.select substr(no,1,3)||to_char(substr(no,4,1)+1) "first missing number"
from
with t as
(select 'ABC1' no from dual
union select 'ABC2' from dual
union select 'ABC3' from dual
union select 'ABC5' from dual
union select 'ABC6' from dual
union select 'ABC8' from dual
select no, lead(no,1,0) over (order by no) next_no from t
where substr(next_no,4,1) - substr(no,4,1) > 1
and rownum = 1; -
Difference of value of a dimension based on min and max
Database: Oracle 10g
BO-BOXIr3
Let me explain the exact problem again.
As per the below code, I have the data in this format in my table:
Code:
Date Site ID KWH
1/2/2009 00:00 IN-1 22
1/2/2009 01:00 IN-1 28
1/3/2009 03:00 IN-2 25
1/3/2009 04:00 IN-2 46
1/4/2009 00:00 IN-3 28
1/4/2009 10:00 IN-3 34
1/5/2009 08:00 IN-4 31
1/5/2009 09:00 IN-4 55
1/5/2009 11:00 IN-4 77
1/6/2009 00:00 IN-5 34
Now want to build a report with following columns:
Site Count KWH
IN-1 2 6 (ex.-28-22)
IN-2 2 21
IN-3 2 6
IN-4 3 46 (ex.-77-31)
IN-5 2 34
SITE- distinct site name.
COUNT-count is number of repetitions of site id between min and max date.
KWH -(Delta between the min and max date)
To get the above result I have created 3 report from different queries since not able to get these al in a single report viz Count, Max Value and Min value. Well I have all these 3 reports or table on a single page.
Count-this report will give the count between the dates
Max Value-this report will give me the values of kwh for max dates for each site id
Min Value-this report will give me the values of kwh for min dates for each site id
Now want to create a single report based on these 3 reports which contains the column
Site|Count|KWH
IS IT POSSIBLE?
Or
Is it possible to build such report in a single one with all the required column which I mentioned?
The variables which I created to get the max & min dates,
Mx_dt= =Max([Query 2].[Hourly]) In ([Query 2].[SITE_ID])
Mn_dt= =Min([Query 3 (12)].[Hourly]) In ([Query 3 (12)].[SITE_ID])
For filtering on report used following variables:
if_st_mn=If([mn_dt])=[Hourly] Then "ok" Else "no"
if_st_mx =If([mx_dt])=[Hourly] Then "ok" Else "no"
will filter on "ok" to get the max and min date values.
rest of the variable in the snap are not usable.Yes, you can do it in one report.
I created a sample report from efashion:
Year | Lines | Sales Revenue
2001 | Accessories | $250
2003 | Accessories | $550
2001 | City Skirts | $1050
2003 | City Skirts | $1150...........
Create 2 variables 1) Count and 2) Difference:
1) Count as formula - =Count([Lines]) In Report
2) Difference as formula - =Sum([Sales revenue]) Where (Max([Year]) In Report = [Year]) - Sum([Sales revenue]) Where (Min([Year]) In Report = [Year])
You can replace the formula with your report variables. Then just drag Site ID, Count and Difference variables to your report.
Thanks
Jai -
Global Change or filter based on Min and Max dates
Hi Guys,
Hopefully there is a genius out there that is an expert with filters and or global changes, I am after a solution and can’t work out if it is possible to do in P6.
Based on a filter (using codes to select a group of activities) I want to write a value into two date UDF Fields can I:
Run a global change to give the earliest and latest date in the group and write the result to all tasks in the group? or
Is there a mindate maxdate option in Global change or filter? Or
If these tasks were grouped in the activity view can a global change be written to fill down the dates that the summary level is displaying, which are essentially the min and max dates of the groups.
I could do this pretty easily in excel but I have over a 100 projects and doing the import one at a time is not feasible.
I could create LOE’s but as my variables are constantly changing and due to the volume also not an option.
Summary bars are not an option eithers as I am writing the UDF’s to get all the bars I want on one line,
An option for me might be to do it using Legare but I would prefer to see if I can get it done in P6 first.
Cheers
RobYes, you can do it in one report.
I created a sample report from efashion:
Year | Lines | Sales Revenue
2001 | Accessories | $250
2003 | Accessories | $550
2001 | City Skirts | $1050
2003 | City Skirts | $1150...........
Create 2 variables 1) Count and 2) Difference:
1) Count as formula - =Count([Lines]) In Report
2) Difference as formula - =Sum([Sales revenue]) Where (Max([Year]) In Report = [Year]) - Sum([Sales revenue]) Where (Min([Year]) In Report = [Year])
You can replace the formula with your report variables. Then just drag Site ID, Count and Difference variables to your report.
Thanks
Jai -
MIN and MAX datetimes ti find range
I am using Oracle 11g version
create table re(Name char(20),Datetime char(45),val1 number);
insert into re values('abc','10/29/2012 13:00','1.5')
insert into re values('abc','10/29/2012 13:05','1.5')
insert into re values('abc','10/29/2012 13:10','1.5')
insert into re values('abc','10/29/2012 13:15','1.5')
insert into re values('abc','10/29/2012 13:20','0.00')
insert into re values('abc','10/29/2012 13:25','0.00')
insert into re values('abc','10/29/2012 13:30','0.00')
insert into re values('abc','10/29/2012 13:35','0.00')
insert into re values('abc','10/29/2012 13:40','2.1')
insert into re values('abc','10/29/2012 13:45','2.3')
insert into re values('abc','10/29/2012 13:50','2.1')
insert into re values('abc','10/29/2012 13:55','2.1')
insert into re values('abc','10/29/2012 14:00','2.2')
O/P:
In this way data is stored in database.Needed output is, I want the datetime column data range with min and max values where val1>0 only.
Expected result while we consider the above data is::
Name mintime maxtime
abc 10/19/2012 13:00 10/19/2012 13:15
abc 10/29/2012 13:40 10/29/2012 14:00
For this I tried something like this,
select name, min(to_date(Datetime ,'mm/dd/yyyy hh24:mi')) start, max(to_date(Datetime ,'mm/dd/yyyy hh24:mi')) end from (
select name, Datetime ,to_date(Datetime ,'mm/dd/yyyy hh24:mi') - rank() over (partition by loc_name order by t1 asc) Val_col from re where val1 > 0
) group by lname, Val_col
but I am getting the output like this for above query.
name start end
abc 10/29/2012 13:00 10/29/2012 13:00
abc 10/29/2012 13:05 10/29/2012 13:05
so.on.
Edited by: 913672 on Apr 3, 2013 3:07 AM913672 wrote:
I am using Oracle 11g version
create table re(Name char(20),Datetime char(45),val1 number);
insert into re values('abc','10/29/2012 13:00','1.5')
insert into re values('abc','10/29/2012 13:05','1.5')
insert into re values('abc','10/29/2012 13:10','1.5')
insert into re values('abc','10/29/2012 13:15','1.5')
insert into re values('abc','10/29/2012 13:20','0.00')
insert into re values('abc','10/29/2012 13:25','0.00')
insert into re values('abc','10/29/2012 13:30','0.00')
insert into re values('abc','10/29/2012 13:35','0.00')
insert into re values('abc','10/29/2012 13:40','2.1')
insert into re values('abc','10/29/2012 13:45','2.3')
insert into re values('abc','10/29/2012 13:50','2.1')
insert into re values('abc','10/29/2012 13:55','2.1')
insert into re values('abc','10/29/2012 14:00','2.2')
O/P:
In this way data is stored in database.Needed output is, I want the datetime column data range with min and max values where val1>0 only.
Expected result while we consider the above data is::
Name mintime maxtime
abc 10/19/2012 13:00 10/19/2012 13:15
abc 10/29/2012 13:40 10/29/2012 14:00
For this I tried something like this,
select name, min(to_date(Datetime ,'mm/dd/yyyy hh24:mi')) start, max(to_date(Datetime ,'mm/dd/yyyy hh24:mi')) end from (
select name, Datetime ,to_date(Datetime ,'mm/dd/yyyy hh24:mi') - rank() over (partition by loc_name order by t1 asc) Val_col from re where val1 > 0
) group by lname, Val_col
but I am getting the output like this for above query.
name start end
abc 10/29/2012 13:00 10/29/2012 13:00
abc 10/29/2012 13:05 10/29/2012 13:05
so.on.Firstly and most importantly do NOT store dates as char columns: that's what the DATE type is for.
Secondly, i'm not sure how you get your output from the input, particularly as your SQL contains 'partition by loc_name' which
doesn't even exist in your example table.
Why has the same name got two rows with those min/max times. Are you partitioning by val1? -
Select just the values between min and max of an accumulated value over day
Hello Forum,
a value is accumulated over a day and over a period of time. Next day the value is reseted and starts again to be accumulated:
with sampledata as (select to_date('09.09.2012 00:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 01:03:08', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 02:54:11', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 03:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 04:04:19', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 05:04:20', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 06:12:02', 'dd.mm.yyyy hh24:mi:ss') ts, 23 val from dual union all
select to_date('09.09.2012 07:12:03', 'dd.mm.yyyy hh24:mi:ss') ts, 29 val from dual union all
select to_date('09.09.2012 08:12:04', 'dd.mm.yyyy hh24:mi:ss') ts, 30 val from dual union all
select to_date('09.09.2012 09:12:11', 'dd.mm.yyyy hh24:mi:ss') ts, 45 val from dual union all
select to_date('09.09.2012 10:12:12', 'dd.mm.yyyy hh24:mi:ss') ts, 60 val from dual union all
select to_date('09.09.2012 11:12:13', 'dd.mm.yyyy hh24:mi:ss') ts, 75 val from dual union all
select to_date('09.09.2012 12:21:24', 'dd.mm.yyyy hh24:mi:ss') ts, 95 val from dual union all
select to_date('09.09.2012 13:21:26', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 14:21:27', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('09.09.2012 15:21:30', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('09.09.2012 16:21:32', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('09.09.2012 17:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('09.09.2012 21:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('09.09.2012 23:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 00:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 01:03:08', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 02:54:11', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 03:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 04:04:19', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 05:04:20', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 06:12:02', 'dd.mm.yyyy hh24:mi:ss') ts, 14 val from dual union all
select to_date('10.09.2012 07:12:03', 'dd.mm.yyyy hh24:mi:ss') ts, 34 val from dual union all
select to_date('10.09.2012 08:12:04', 'dd.mm.yyyy hh24:mi:ss') ts, 58 val from dual union all
select to_date('10.09.2012 09:12:11', 'dd.mm.yyyy hh24:mi:ss') ts, 70 val from dual union all
select to_date('10.09.2012 10:12:12', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('10.09.2012 11:12:13', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 12:21:24', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual union all
select to_date('10.09.2012 13:21:26', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual union all
select to_date('10.09.2012 14:21:27', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual union all
select to_date('10.09.2012 15:21:30', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual union all
select to_date('10.09.2012 16:21:32', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual union all
select to_date('10.09.2012 21:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual)
select ts, val
from sampledata
order by ts asc;How should I change the select statement to skip all data sets before the first minimum and the duplicates after the maximum of a day in order to get such a result:
TS VAL
09.09.12 06:12 23
09.09.12 07:12 29
09.09.12 08:12 30
09.09.12 09:12 45
09.09.12 10:12 60
09.09.12 11:12 75
09.09.12 12:21 95
09.09.12 13:21 120
09.09.12 14:21 142
10.09.12 06:12 14
10.09.12 07:12 34
10.09.12 08:12 58
10.09.12 09:12 70
10.09.12 10:12 120
10.09.12 11:12 142
10.09.12 12:21 153Thank youThis solution works perfectly when the accumulated value has its low and its high on the same day. But I found out :( , that there is also data, which has its low yesterday and its high today. For a better understandig of the case, there is a machine, wich is working over 3 Shifts with irregular start and end time. For example Shift1 cann start at 5:50 or at 7:15. The accumulated value of the worked time is accumuated for each shift extra. This solution works for the shift 1 (approximate between 06:00-14:00) and for the shift 2(approximate between 14:00-22:00), because there is the low and the high of the accumulated value on the same day. This solution does not work for the shif 3(approximate between 22:00-06:00), because the high of the accumulated value is or can be the next day.
So the thread title should be: "Select just the values between min and max of an accumulated value over the same day(today) or over two successive days (yesterday and today)
Sampledata for shift 1 or shift 2:
{code}
with sampledata as (select to_date('09.09.2012 00:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 01:03:08', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 02:54:11', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 03:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 04:04:19', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 05:04:20', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 06:12:02', 'dd.mm.yyyy hh24:mi:ss') ts, 23 val from dual union all
select to_date('09.09.2012 07:12:03', 'dd.mm.yyyy hh24:mi:ss') ts, 29 val from dual union all
select to_date('09.09.2012 08:12:04', 'dd.mm.yyyy hh24:mi:ss') ts, 30 val from dual union all
select to_date('09.09.2012 09:12:11', 'dd.mm.yyyy hh24:mi:ss') ts, 45 val from dual union all
select to_date('09.09.2012 10:12:12', 'dd.mm.yyyy hh24:mi:ss') ts, 60 val from dual union all
select to_date('09.09.2012 11:12:13', 'dd.mm.yyyy hh24:mi:ss') ts, 75 val from dual union all
select to_date('09.09.2012 12:21:24', 'dd.mm.yyyy hh24:mi:ss') ts, 95 val from dual union all
select to_date('09.09.2012 13:21:26', 'dd.mm.yyyy hh24:mi:ss') ts, 120 val from dual union all
select to_date('09.09.2012 14:21:27', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('09.09.2012 15:21:30', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('09.09.2012 16:21:32', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('09.09.2012 17:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('09.09.2012 21:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('09.09.2012 23:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 00:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 01:03:08', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 02:54:11', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 03:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 04:04:19', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 05:04:20', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 06:12:02', 'dd.mm.yyyy hh24:mi:ss') ts, 143 val from dual union all
select to_date('10.09.2012 07:12:03', 'dd.mm.yyyy hh24:mi:ss') ts, 144 val from dual union all
select to_date('10.09.2012 08:12:04', 'dd.mm.yyyy hh24:mi:ss') ts, 145 val from dual union all
select to_date('10.09.2012 09:12:11', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 10:12:12', 'dd.mm.yyyy hh24:mi:ss') ts, 147 val from dual union all
select to_date('10.09.2012 11:12:13', 'dd.mm.yyyy hh24:mi:ss') ts, 148 val from dual union all
select to_date('10.09.2012 12:21:24', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual union all
select to_date('10.09.2012 13:21:26', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual union all
select to_date('10.09.2012 14:21:27', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual union all
select to_date('10.09.2012 15:21:30', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual union all
select to_date('10.09.2012 16:21:32', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual union all
select to_date('10.09.2012 21:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 153 val from dual)
, got_analytics AS
SELECT ts, val
, MIN (val) OVER ( PARTITION BY TRUNC (ts)
ORDER BY ts DESC
) AS min_val_after
, CASE
WHEN ROW_NUMBER () OVER ( PARTITION BY TRUNC (ts)
ORDER BY val
, ts
) = 1
THEN -1 -- Impossibly low val
ELSE LAG (val) OVER ( PARTITION BY TRUNC (ts)
ORDER BY ts
END AS prev_val
, MIN (val) OVER (PARTITION BY TRUNC (ts))
AS low_val_today
, NVL ( LAST_VALUE (val) OVER ( ORDER BY ts
RANGE BETWEEN UNBOUNDED PRECEDING
AND ts - TRUNC (ts) PRECEDING
, -1
) AS last_val_yesterday
FROM sampledata
SELECT ts
, val
FROM got_analytics
WHERE val <= min_val_after
AND val > prev_val
AND ( val > low_val_today
OR val != last_val_yesterday
ORDER BY ts
{code}
with the expected results:
{code}
1 09.09.2012 06:12:02 23
2 09.09.2012 07:12:03 29
3 09.09.2012 08:12:04 30
4 09.09.2012 09:12:11 45
5 09.09.2012 10:12:12 60
6 09.09.2012 11:12:13 75
7 09.09.2012 12:21:24 95
8 09.09.2012 13:21:26 120
9 09.09.2012 14:21:27 142
10 10.09.2012 06:12:02 143
11 10.09.2012 07:12:03 144
12 10.09.2012 08:12:04 145
13 10.09.2012 09:12:11 146
14 10.09.2012 10:12:12 147
15 10.09.2012 11:12:13 148
16 10.09.2012 12:21:24 153
{code}
And the sampledata for shift 3 is:
{code}
with sampledata as (select to_date('08.09.2012 00:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 23 val from dual union ALL
select to_date('08.09.2012 02:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 45 val from dual union all
select to_date('08.09.2012 05:03:08', 'dd.mm.yyyy hh24:mi:ss') ts, 78 val from dual union all
select to_date('08.09.2012 06:54:11', 'dd.mm.yyyy hh24:mi:ss') ts, 90 val from dual union all
select to_date('08.09.2012 08:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 90 val from dual union all
select to_date('08.09.2012 10:04:19', 'dd.mm.yyyy hh24:mi:ss') ts, 90 val from dual union all
select to_date('08.09.2012 12:04:20', 'dd.mm.yyyy hh24:mi:ss') ts, 90 val from dual union all
select to_date('08.09.2012 16:12:02', 'dd.mm.yyyy hh24:mi:ss') ts, 90 val from dual union all
select to_date('08.09.2012 17:12:03', 'dd.mm.yyyy hh24:mi:ss') ts, 90 val from dual union all
select to_date('08.09.2012 19:12:04', 'dd.mm.yyyy hh24:mi:ss') ts, 90 val from dual union all
select to_date('08.09.2012 21:12:11', 'dd.mm.yyyy hh24:mi:ss') ts, 90 val from dual union all
select to_date('08.09.2012 22:00:12', 'dd.mm.yyyy hh24:mi:ss') ts, 24 val from dual union all
select to_date('08.09.2012 22:12:13', 'dd.mm.yyyy hh24:mi:ss') ts, 40 val from dual union all
select to_date('08.09.2012 23:21:24', 'dd.mm.yyyy hh24:mi:ss') ts, 68 val from dual union all
select to_date('09.09.2012 01:03:08', 'dd.mm.yyyy hh24:mi:ss') ts, 79 val from dual union all
select to_date('09.09.2012 02:54:11', 'dd.mm.yyyy hh24:mi:ss') ts, 124 val from dual union all
select to_date('09.09.2012 03:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 125 val from dual union all
select to_date('09.09.2012 04:04:19', 'dd.mm.yyyy hh24:mi:ss') ts, 126 val from dual union all
select to_date('09.09.2012 05:04:20', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 06:12:02', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 07:12:03', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 08:12:04', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 09:12:11', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 10:12:12', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 11:12:13', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 12:21:24', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 13:21:26', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 14:21:27', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 15:21:30', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 16:21:32', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 17:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union all
select to_date('09.09.2012 21:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 127 val from dual union ALL
select to_date('09.09.2012 22:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 5 val from dual union ALL
select to_date('09.09.2012 22:51:33', 'dd.mm.yyyy hh24:mi:ss') ts, 23 val from dual union all
select to_date('09.09.2012 23:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 40 val from dual union all
select to_date('10.09.2012 00:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 50 val from dual union all
select to_date('10.09.2012 01:03:08', 'dd.mm.yyyy hh24:mi:ss') ts, 60 val from dual union all
select to_date('10.09.2012 02:54:11', 'dd.mm.yyyy hh24:mi:ss') ts, 78 val from dual union all
select to_date('10.09.2012 03:04:08', 'dd.mm.yyyy hh24:mi:ss') ts, 142 val from dual union all
select to_date('10.09.2012 04:04:19', 'dd.mm.yyyy hh24:mi:ss') ts, 145 val from dual union all
select to_date('10.09.2012 05:04:20', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 06:12:02', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 07:12:03', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 08:12:04', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 09:12:11', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 10:12:12', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 11:12:13', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 12:21:24', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 13:21:26', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 14:21:27', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 15:21:30', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 16:21:32', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual union all
select to_date('10.09.2012 21:21:33', 'dd.mm.yyyy hh24:mi:ss') ts, 146 val from dual)
, got_analytics AS
SELECT ts, val
, MIN (val) OVER ( PARTITION BY TRUNC (ts)
ORDER BY ts DESC
) AS min_val_after
, CASE
WHEN ROW_NUMBER () OVER ( PARTITION BY TRUNC (ts)
ORDER BY val
, ts
) = 1
THEN -1 -- Impossibly low val
ELSE LAG (val) OVER ( PARTITION BY TRUNC (ts)
ORDER BY ts
END AS prev_val
, MIN (val) OVER (PARTITION BY TRUNC (ts))
AS low_val_today
, NVL ( LAST_VALUE (val) OVER ( ORDER BY ts
RANGE BETWEEN UNBOUNDED PRECEDING
AND ts - TRUNC (ts) PRECEDING
, -1
) AS last_val_yesterday
FROM sampledata
SELECT ts
, val
FROM got_analytics
WHERE val <= min_val_after
AND val > prev_val
AND ( val > low_val_today
OR val != last_val_yesterday
ORDER BY ts
{code}
with the unexpected results:
{code}
- ts val
1 08.09.2012 00:04:08 23
2 08.09.2012 22:12:13 40
3 08.09.2012 23:21:24 68
4 09.09.2012 22:21:33 5
5 09.09.2012 22:51:33 23
6 09.09.2012 23:21:33 40
7 10.09.2012 00:04:08 50
8 10.09.2012 01:03:08 60
9 10.09.2012 02:54:11 78
10 10.09.2012 03:04:08 142
11 10.09.2012 04:04:19 145
12 10.09.2012 05:04:20 146
{code}
The result should be:
{code}
- ts val
1 08.09.2012 00:04:08 23
2 08.09.2012 02:04:08 45
3 08.09.2012 05:03:08 78
4 08.09.2012 06:54:11 90
5 08.09.2012 22:00:12 24
6 08.09.2012 22:12:13 40
7 08.09.2012 23:21:24 68
8 09.09.2012 01:03:08 79
9 09.09.2012 02:54:11 124
10 09.09.2012 03:04:08 125
11 09.09.2012 04:04:19 126
12 09.09.2012 05:04:20 127
13 09.09.2012 22:21:33 5
14 09.09.2012 22:51:33 23
15 09.09.2012 23:21:33 40
16 10.09.2012 00:04:08 50
17 10.09.2012 01:03:08 60
18 10.09.2012 02:54:11 78
19 10.09.2012 03:04:08 142
20 10.09.2012 04:04:19 145
21 10.09.2012 05:04:20 146
{code}
Thank you for your help! -
i am currently using labview 7.0 and working on agilent 4195A. i am working on this programme where i have to locate the min and max point from the graph so as to locate the resonance frequency. but i tried several derivatives but none of them succeed in helping me to locate my min and max. if anyone have any idea, please let me know. thank you.
Attachments:
mapping.vi 121 KBHi tyl,
well you are using LV7.1...
I made some comments in your vi - please read the development style guide!
Why don't you use the array min/max operation to get the strongest signal output?
And please provide some test data - nobody here can test your vi without proper hardware, without your signal, with missing subvis...
Message Edited by GerdW on 06-22-2007 10:30 AM
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome
Attachments:
mapping.vi 122 KB -
Read the min and max occurrence from XSD
Hi,
I have a scenario where I have an XML, but not its XSD so my question is of two fold
1. Is it possible to create an XSD from that XML, if possible how?
2. Assume I get the XSD how do I read the min and max occurrence from that XSD?
PS: I am coding in java and pretty new to it, so it would be really helpful if I get the code snippets for the same :)
Edited by: Harsha.Hegde on Sep 2, 2008 5:49 AMHarsha.Hegde wrote:
Hi,
I have a scenario where I have an XML, but not its XSD so my question is of two fold
1. Is it possible to create an XSD from that XML, yes
if possible how?by using a text editor, tools, etc.
2. Assume I get the XSD how do I read the min and max occurrence from that XSD?sigh
PS: I am coding in java and pretty new to itthen you should take some time to learn the basics, then work your way into XML after you have a grasp on things conceptually.
so it would be really helpful if I get the code snippets for the same :)sorry, no handouts here
do your own work
come back when you're written some Java and have a technical question -
Avg, Min and Max with a serious twist.....ASO
Hi,
I need to calc the Avg, Min and Max on Revenue. That's simple. However Every row of data the revenue falls into a bucket/range. For example revenue is in buckets '0 to 50' or '51 to 100' or '101 to 150' lets say. As I load data I load a '1' into a 'Count' measure depending on which bucket that row of data falls into. So I can get a total count for each bucket. So '0 to 50' might have a Count of 3. '51 to 100' might also have 3 and '101 to 150' has a 2. So my range count looks like:
0 to 50 - 3
51 to 100 - 3
101 to 150 -2
The trick is they only want the Avg, Min and Max on the rows that makeup the highest 'Count'. In this case that's 3. Problem is there are two ranges that meet this criteria. When that happens they want the Min, Max and Avg of the rows that make up the '51 to 100' bucket since it's the highest range.
I can easily get the '3' by using the Max formula. So I know what the highest bucket is. Problem is I can't figure out for the life of me, how to pass only those rows that make up the '51 to 100' bucket into the Avg, Min and Max function.....
I'm stumped and in dire need of something here. I have a spreadsheet that explains the problem better. If somehow I can get a flag on those rows I can easily Avg, Min and Max it. I just can't seem to figure out how to get a flag on only those rows of data.
I'm willing to share my mocked up example and spreadsheet and .otl and sample data etc....
Please help :)Why does this verify with Min?
Min ( Filter ( CROSSJOIN ( Descendants ( [Service].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Segment].CurrentMember),
Filter ( CROSSJOIN ( Leaves ( [Ranges].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Customer Type].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Zip Code].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Disposal Option].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Tickets].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Yardages].CurrentMember),
Filter ( Descendants ( [Contract Year].CurrentMember),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) ) , [FHRev] )
And when I just change to Tail and put a 1 at the end it fails?
Tail ( Filter ( CROSSJOIN ( Descendants ( [Service].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Segment].CurrentMember),
Filter ( CROSSJOIN ( Leaves ( [Ranges].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Customer Type].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Zip Code].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Disposal Option].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Tickets].CurrentMember),
Filter ( CROSSJOIN ( Descendants ( [Yardages].CurrentMember),
Filter ( Descendants ( [Contract Year].CurrentMember),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) )),
[High Range Max] = ( [High Range Max] , [All FHRev Ranges] ) ) , 1 ) -
Find min and max from a bunch of numbers
hi,
i have a bunch of numbers, and i need to find the min and max.
so i have a arraylist which contains objects....whats the best way to find the min number and max number of all these objects?
thanksYou're close, but you can do them all at the same time without temp variables..
double maximumX = 0;
double minimumX = 0;
double maximumY = 0;
double minimumY = 0;
for (int i = 0; i < myobjects.size(); i++) {
mything d2d = (mything) myobjects.get(i);
maximumX = Math.max(d2d.getBounds().getMaxX(), maximumX);
minimumX= Math.min(d2d.getBounds().getMinX(), minimumX);
maximumY = Math.max(d2d.getBounds().getMaxY(), maximumY);
minimumY = Math.min(d2d.getBounds().getMinY(), minimumY);
}Since you are dealing with rectangles, you could add them all to an Area and get the bounds of the Area, but that's probably slower. -
How much does it cost to replace the Ipad glass? Min and Max?
How much does it cost to replace the Ipad glass? Min and Max?
Apple does not repair iPads, but will replace the entire iPad for a flat fee. If you have AppleCare+ on the iPad, the cost will be relatively minimal; $49 in the US. Otherwise, see the Service Pricing section here:
http://www.apple.com/support/ipad/service/faq/
There are independent iPad repair services that may be able to replace the screen for less. Do a web search for "ipad repair". You can also look for parts and instructions and do the repair yourself. Note, though, that if you elect to have the iPad serviced by an unauthorized shop or perform your own repair, you will get no further support from Apple.
Regards.
Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Communities page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums and in the Apple Knowledge Base, before you post a question. -
Find more than one min and max in 2D array contain 0 rows
Hi
I have a 2D array and I would like to find the max and min elements between series of 0s. As you can see in the picture If I remove all 0s from the array and use the max and min function then I will have just one min and one max but I need to find min and max after every 0 rows so you can see from the picture ( just as an example) I will have 3 min and 3 max numbers. Would you please help me with this code. Do you now any algorithm that can find min and max between 0s?
I have also attached my code to remove 0s and then search for max and min numbers but as I mentioned I need min and max for every part
Many thanks
Attachments:
2.jpg 82 KB
3.jpg 27 KBThanks altenbach
I have attached the vi to this post. I would really apperciate if you help me with this example. The min values should be 100, 1500 and 4000 and the max values should be 1200,2600,5400 so as u mentioned the output should be this 2D array
100,1200
1500,2600
4000,5400
Attachments:
new.vi 6 KB -
Performance Issue using min() and max() in one SQL statement
I have a simple query that selects min() and max() from one column in a table in one sql statment.
The table has about 9 Million rows and the selected column has a non unique index. The query takes 10 secs. When i select min() and max() in separate statements, each takes only 10 msecs:
This statement takes 10 secs:
select min(date_key) , max(date_key)
from CAPS_KPIC_BG_Fact_0_A
where date_key != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD'))
This statement takes 10 msecs:
select min(date_key)
from MYTABLE
where date_key != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD'))
union all
select max(date_key) from MYTABLE
Because the first statement is part of an autmatic generated SQL of an application, i can't change it and i have to optimize the data model. How can i speed up the first statement?I've ran similar query on a table that has 10 milliion rows, with an index on the date column
This is what I have found:
SQL> set timing on
1 SELECT MIN(ID_DATE) MIN_DATE, MAX(ID_DATE) MAX_DATE
2 FROM MY_DATE
3* WHERE ID_DATE != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD'))
SQL> /
MIN_DATE MAX_DATE
03-APR-76 06-JAN-02
real: 43383
SQL> SELECT MIN(ID_DATE) MIN_DATE FROM MY_DATE
2 WHERE ID_DATE != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD'))
3 UNION ALL
4 SELECT MAX(ID_DATE) MAX_DATE FROM MY_DATE
5 WHERE ID_DATE != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD'))
6 /
MIN_DATE
03-APR-76
06-JAN-02
real: 20
SQL> SELECT MIN_DATE, MAX_DATE FROM
2 (SELECT MAX(ID_DATE) MAX_DATE FROM MY_DATE
3 WHERE ID_DATE != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD')) ) A,
4 (SELECT MIN(ID_DATE) MIN_DATE FROM MY_DATE
5 WHERE ID_DATE != TO_DATE(('1900-1-1' ),( 'YYYY-MM-DD')) ) B
6 /
MIN_DATE MAX_DATE
03-APR-76 06-JAN-02
real: 10
SQL> My conculsion, there is nothing you can do to the tables that will improve that particular statement.
Why can't you modify the application?
Maybe you are looking for
-
Dear Expert, After Upgrade I can not mapping cost element to cost center in ECC 6.0 using transaction code OKB9. Can you help me. Thank you. Regards, MAL
-
Compiling Apache 2.2 and php 5.2 from source on Arch
Hi there Wanting to compile Apache 2 with PHP 5 on my Arch server. I figure this must be frequently done by people out there wanting more control over how their servers are setup, and was wondering if anyone had some good documentation for this? If n
-
Null pointer exception with JavaCompiler interface
Hi, I am trying to compile a java file from another java source. My files are- Cmp.java ====== public class Cmp { public static void main(String args[]) throws Exception{ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); int result = comp
-
Am i on the right track for establishing my client connection with BC4J?
I am developing web-application with BC4J JSP project now. However, I find the auto-generated page not that useful as they are not flexible enough. Then, I decided to write coding by myself. But the first problem is - how to write the coding for clie
-
Veritas Netbackup Client Installed on Solaris 10 Zone Unable to Work
Hi I am having problems with Veritas Netbackup client which had been installed on a Solaris 10 zone only. We are using Veritas Netbackup server which is installed on a Windows 2000 server and the NBU server is unable to add the new client for backup.