Max and sum in a query using Group by and dense_rank

Hi all

I am running Oracle 10 G on Windows 2003.

I have two tables, RT_DY_ZONE1EDYCONS and MV_ZONE_HOURLY. I need a query that will give me the SUM of MR_OL01_VT of RT_DY_ZONE1EDYCONS for each month and the maximum value of MR_OL01_FI_0S and MR_OL02_FI_0S and the time of the maximum value for each group for the month of MV_ZONE_HOURLY. I can't combine the two querys I came up with these forums in a single search.

I need the following result, any help would be appreciated.
datetime, SUM of MR_OL01_VT , max value MR_OL01_FI_0S ,max_time MR_OL01_FI_0S , max value MR_OL02_FI_0S ,max_time MR_OL02_FI_0S
January 2010,8.373765,4.96935,2010-01-15:01,5.96835,2010-01-15:17
I used the following query to obtain the SUM of the MR_OL01_VT
SELECT 
    TRUNC(VOL.TIMESTAMP, 'MM') datetime, 
    SUM(VOL.MR_OL01_VT) 
FROM 
    RT_DY_ZONE1EDYCONS VOL 
GROUP BY 
    TRUNC(VOL.TIMESTAMP, 'MM')
ORDER BY
    TRUNC(VOL.TIMESTAMP, 'MM')
and this query for the maximum value/time MR_OL01_FI_0S and MR_OL02_FI_0S
select TAG_NAME,
       max(tag_avg) keep (dense_rank last order by tag_avg) over (partition by tag_name) Max_Value,
       max(datetime) keep (dense_rank last order by tag_avg) over (partition by tag_name) AS MAX_DATE
from mv_zone_hourly
WHERE tag_name LIKE 'MR_OL0%_FI_0S'
first table
CREATE TABLE RT_DY_ZONE1EDYCONS 
   (     TIMESTAMP DATE NOT NULL ENABLE, 
     HB_OL00_VT NUMBER(12,6), 
     OR_RES0_VT NUMBER(12,6), 
     OP_OL01_VT NUMBER(12,6), 
     FP_OL01_VT NUMBER(12,6), 
     BD_OL01_VT NUMBER(12,6), 
     MR_OL01_VT NUMBER(12,6), 
     Z1E_VT NUMBER(12,6)
)
with the sample data
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:00','YYYY-MM-DD:HH24'),4.443056,1.088,1.224927,0.663266,0,0.387499,1.079364);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:01','YYYY-MM-DD:HH24'),4.352083,null,0.692914,0.044029,0,0.373536,null);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:02','YYYY-MM-DD:HH24'),null,null,null,null,0,null,null);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:03','YYYY-MM-DD:HH24'),4.300694,null,0.662924,0,0,0.380275,null);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:04','YYYY-MM-DD:HH24'),null,null,null,null,0,null,null);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:05','YYYY-MM-DD:HH24'),0.025694,null,0.650406,0,0,0.342299,null);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:06','YYYY-MM-DD:HH24'),null,null,null,null,0,null,null);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:07','YYYY-MM-DD:HH24'),0.122917,-2.992,0.673062,0,0,0.423474,2.018381);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:08','YYYY-MM-DD:HH24'),0.106944,null,1.27403,0.768119,0,0.449303,null);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:09','YYYY-MM-DD:HH24'),null,null,null,null,0,null,null);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:10','YYYY-MM-DD:HH24'),0.122917,-2.448,0.637977,0,0,0.418056,1.514884);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:11','YYYY-MM-DD:HH24'),0.183333,-2.992,0.649855,0,0,0.401947,2.123531);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:12','YYYY-MM-DD:HH24'),1.157639,-2.992,1.039931,0.463684,0,0.43389,2.212134);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:13','YYYY-MM-DD:HH24'),4.536111,1.36,0.972226,0.381604,0,0.461941,1.36034);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:14','YYYY-MM-DD:HH24'),4.496528,2.176,0.647979,0,0,0.45611,1.216439);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:15','YYYY-MM-DD:HH24'),4.409028,2.72,0.665355,0,0,0.440141,0.583532);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:16','YYYY-MM-DD:HH24'),4.380556,1.36,0.886389,0.256387,0,0.429446,1.448334);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:17','YYYY-MM-DD:HH24'),4.433333,0.272,1.21716,0.656324,0,0.434169,1.85368);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:18','YYYY-MM-DD:HH24'),4.409722,2.176,0.653266,0,0,0.436253,1.144203);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:19','YYYY-MM-DD:HH24'),4.44375,2.448,0.67917,0,0,0.436947,0.879633);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:20','YYYY-MM-DD:HH24'),4.420833,0,1.273057,0.733813,0,0.428474,1.985489);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:21','YYYY-MM-DD:HH24'),4.390278,2.176,0.895212,0.280419,0,0.418195,0.620452);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:22','YYYY-MM-DD:HH24'),4.336806,1.904,0.670843,0,0,0.412711,1.349252);
Insert into RT_DY_ZONE1EDYCONS (TIMESTAMP,HB_OL00_VT,OR_RES0_VT,OP_OL01_VT,FP_OL01_VT,BD_OL01_VT,MR_OL01_VT,Z1E_VT) values (to_date('2010-01-15:23','YYYY-MM-DD:HH24'),4.305556,2.448,0.689441,0,0,0.409099,0.759016);
and the second table
CREATE TABLE MV_ZONE_HOURLY
( TAG_NAME VARCHAR2(30),
  TAG_DESCRIP VARCHAR(100),
  DATETIME DATE,
  TAG_AVG NUMBER(12,6)
)
with the sample data
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:00','YYYY-MM-DD:HH24'),4.166712);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:01','YYYY-MM-DD:HH24'),4.96935);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:02','YYYY-MM-DD:HH24'),4.367);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:03','YYYY-MM-DD:HH24'),4.67788);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:04','YYYY-MM-DD:HH24'),4.06335);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:05','YYYY-MM-DD:HH24'),3.23456);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:06','YYYY-MM-DD:HH24'),4.2333555);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:07','YYYY-MM-DD:HH24'),4.5890);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:08','YYYY-MM-DD:HH24'),4.166712);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:09','YYYY-MM-DD:HH24'),4.96735);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:10','YYYY-MM-DD:HH24'),4.8456);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:11','YYYY-MM-DD:HH24'),4.2468);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:12','YYYY-MM-DD:HH24'),4.06335);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:13','YYYY-MM-DD:HH24'),3.9746);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:14','YYYY-MM-DD:HH24'),4.2333555);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:15','YYYY-MM-DD:HH24'),4.47);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:16','YYYY-MM-DD:HH24'),4.166712);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:17','YYYY-MM-DD:HH24'),4.96835);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:18','YYYY-MM-DD:HH24'),4.6890);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:19','YYYY-MM-DD:HH24'),4.42345);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:20','YYYY-MM-DD:HH24'),4.06335);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:21','YYYY-MM-DD:HH24'),3.4579);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:22','YYYY-MM-DD:HH24'),4.2333555);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL01_FI_0S','Montreal Rd Disch Flow 1',to_date('2010-01-15:23','YYYY-MM-DD:HH24'),4.45789);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:00','YYYY-MM-DD:HH24'),5.166712);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:01','YYYY-MM-DD:HH24'),5.97835);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:02','YYYY-MM-DD:HH24'),5.367);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:03','YYYY-MM-DD:HH24'),5.67788);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:04','YYYY-MM-DD:HH24'),5.06335);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:05','YYYY-MM-DD:HH24'),4.23456);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:06','YYYY-MM-DD:HH24'),5.2333555);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:07','YYYY-MM-DD:HH24'),5.5890);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:08','YYYY-MM-DD:HH24'),5.166712);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:09','YYYY-MM-DD:HH24'),5.95635);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:10','YYYY-MM-DD:HH24'),5.8456);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:11','YYYY-MM-DD:HH24'),5.2468);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:12','YYYY-MM-DD:HH24'),5.06335);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:13','YYYY-MM-DD:HH24'),4.9746);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:14','YYYY-MM-DD:HH24'),5.2333555);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:15','YYYY-MM-DD:HH24'),5.47);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:16','YYYY-MM-DD:HH24'),5.166712);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:17','YYYY-MM-DD:HH24'),5.96835);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:18','YYYY-MM-DD:HH24'),5.6890);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:19','YYYY-MM-DD:HH24'),5.42345);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:20','YYYY-MM-DD:HH24'),5.06335);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:21','YYYY-MM-DD:HH24'),4.4579);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:22','YYYY-MM-DD:HH24'),5.2333555);
Insert into MV_ZONE_HOURLY (TAG_NAME,TAG_DESCRIP,DATETIME,TAG_AVG) values ('MR_OL02_FI_0S','Montreal Rd Disch Flow 2',to_date('2010-01-15:23','YYYY-MM-DD:HH24'),5.45789);

Hello

Thanks for posting the CREATE TABLE and INSERT statements; This is really useful!

Your volumninous sample data are all for a month. Since your first query is grouped by month, I suppose that this is not always the case.
In this case, you can make GROUP BY queries on two tables separately, in two subqueries, then join the results.
For the separate columns for the values of mv_zone_hoiurly, I GROUP BY the name of tag in the subquery, then their pivot in two columns in the query of amin.

WITH     edycons_summary       AS
(
     SELECT       TRUNC (tmstmp, 'MM')     AS mnth
     ,       SUM (mr_ol01_vt)     AS sum_mr_ol01_vt
     FROM       rt_dy_zone1edycons
     GROUP BY  TRUNC (tmstmp, 'MM')
)
,     hourly_summary       AS
(
     SELECT       tag_name
     ,       TRUNC (datetime, 'MM')     AS mnth
     ,       MAX (tag_avg)                  AS max_avg
     ,       MAX (datetime) KEEP (DENSE_RANK LAST ORDER BY tag_avg NULLS FIRST)
                                          AS max_avg_datetime
     FROM       mv_zone_hourly
     WHERE       tag_name     IN ( 'MR_OL01_FI_0S'
                         , 'MR_OL02_FI_0S'
                       )
     GROUP BY  tag_name
     ,            TRUNC (datetime, 'MM')
)
SELECT       TO_CHAR (v.mnth, 'fmMonth YYYY')     AS datetime
,       v.sum_mr_ol01_vt
,       MAX ( CASE
                 WHEN  h.tag_name = 'MR_OL01_FI_0S'
              THEN  h.max_avg
             END
           )                         AS max_avg_01
,       MAX ( CASE
                 WHEN  h.tag_name = 'MR_OL01_FI_0S'
              THEN  h.max_avg_datetime
             END
           )                         AS datetime_01
,       MAX ( CASE
                 WHEN  h.tag_name = 'MR_OL02_FI_0S'
              THEN  h.max_avg
             END
           )                         AS max_avg_02
,       MAX ( CASE
                 WHEN  h.tag_name = 'MR_OL02_FI_0S'
              THEN  h.max_avg_datetime
             END
           )                         AS datetime_02
FROM       edycons_summary     v
JOIN       hourly_summary     h     ON     h.mnth     = v.mnth
GROUP BY  v.mnth
,            v.sum_mr_ol01_vt
;

Tags: Database

Similar Questions

  • Problem with subtotal and grand total using GROUP BY ROLLUP.

    Hi all

    I have a question about the SQL. I need to have the subtotal for each group and total for the entire inside of my request. I've had using GROUP BY ROLLUP to have total subtotal and big inside of my request.

    However, it not successful I want. In addition, my data must be presented in the medium hierarchy. So, I also use CONNECT BY permission inside my request.

    The query returned the results but not as my expected.

    Below is all about the tools used, description of flows, issues, query used, sample data, out of the request as well as the expected results: -.

    Tools used: -.

    • Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    Description of the flow: -.

    Lily is an AM of agency which is the highest level of management (LEVEL 1). Kevin is the direct agent under the lilies and the sum of productivity(upstream)

    for each of them must be sum up as the Subtotal. Sarah and Tom is the Unit Manager (UM) (LEVEL 2) who reports to Lily. They have the direct agents (Agent) under each of them which are may, John, Sue and Salwa (LEVEL 3).  There should be a Subtotal for each group of the agent. For example:-May (Agent) is the agent under Sarah (UM) and both of them have productivity and productivity should be sum up as a subtotal for the core group. A GRAND TOTAL is required to summarize all the productivity for each group.

    Problem: -.

    1. The output of my query is appear the subtotal, but the amount is inaccurate because it only to summarize the productivity of agent. The output I expect is summarize the productivity of the agent as well as UNIFIED messaging / AM. For example:-(subtotal = UM / AM.) THE PRODUCTIVITY + AGENT. PRODUCTIVITY)
    2. The total general does not show after the query. The output that I expected is productivity for each groups as shown in the attachment below.                                                   For example:- GRAND TOTAL =(SUBTOTAL+SUBTOTAL+SUBTOTAL)
    3. My data must be submitted in respect of the hierarchy as below: -.

    4. I need to pass the variable in the query and be used as a parameter in the ADF. Agent ID of Lily(AM) pass in the variable as a parameter.

    Here's my query: -.

    SELECT LPAD (' ', 4 *(LEVEL-1))

    || NAME FIRST_NAMEQ,

    TOTAL_MANPOWER,

    SUM_MTD_TOTAL_ANP UPSTREAM,

    level,

    A_AGENT_ID

    Of

    (SELECT B.SID,

    A.UPLINE,

    A.AGENT_ID AS A_AGENT_ID,

    GROUPING (B.SID) agg_am_id,

    GROUPING (A.AGENT_ID) agg_um_id,

    GROUPING (A.Upline) agg_IM_id,

    SUM (B.TOTAL_MANPOWER) TOTAL_MANPOWER,

    SUM (B.MTD_TOTAL_ANP) SUM_MTD_TOTAL_ANP

    OF ABM_AGENT_TEST,.

    ABM_PRODUCTIVITY B

    WHERE A.AGENT_ID = B.AGENT_ID

    ROLLUP GROUP ((A.UPLINE), (A.AGENT_ID, B.SID)))

    START WITH A_AGENT_ID =: HAS

    CONNECT BY PRIOR A_AGENT_ID = UPSTREAM

    ORDER OF FRIARS UPSTREAM;

    Below is the query to create the table and also the data: -.

    -TABLE ABM_AGENT_TEST-

    CREATE TABLE 'ABM_AGENT_TEST '.

    (NUMBER OF 'AGENT_ID',

    VARCHAR2 (50 BYTE) "NAME."

    VARCHAR2 (10 BYTE) "GRADE."

    VARCHAR2 (20 BYTE) "UPSTREAM."

    'REGION' VARCHAR2 (20 BYTE),

    "BRANCH" VARCHAR2 (20 BYTE),

    'THE AGENCY' VARCHAR2 (20 BYTE)

    )

    SAMPLE DATA FROM ABM_AGENT_TEST

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (116, "Lily", "AM", null, null, null, null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (102, 'Tom', 'MU', '116', null, null, null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (110, 'Sarah', 'MU', '116', null, null, null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (100, 'John', 'AGENT', '102', 'Central', 'PJ', 'CPA');

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (109, "Salwa", 'AGENT', '102', 'South', 'MLK', null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (101, 'Howard', 'AGENT', '102', 'North', "Damansara", "AP");

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (103, 'Mary', 'AGENT', '102', 'Central', 'PJ', 'CPA');

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (106, 'Ali', 'AGENT', '110', 'Central', 'JlnPd', null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (111, 'Sue', 'AGENT', '102', 'North', "Damansara", null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (112, "Carron', 'AGENT', '102', 'Central', 'HQ', null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (113, "Siti', 'AGENT', '102', 'Central', 'PJ', null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (114, "Siti FHIMA Dane forecastle', 'AGENT', '102', 'North',"Damansara", null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (105, 'Kathy', 'AGENT', '102', 'Central', 'JlnPd', 'LPK');

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (107, 'Roby', 'AGENT', '110', 'North', "IPH", null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (108, 'Tommy', 'AGENT', '110', 'South', 'MLK', null);

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (104, 'May', 'AGENT', '110', 'Central', 'HQ', 'CPA');

    Insert into ABM_AGENT_TEST (AGENT_ID, NAME, GRADE, upstream, REGION, BRANCH, AGENCY) values (115, 'Kevin', 'AGENT', '116', 'North', "IPH", null);

    -TABLE ABM_PRODUCTIVITY-

    CREATE TABLE 'JEROMEWALTER '. "" ABM_PRODUCTIVITY ".

    (NUMBER OF 'AGENT_ID',

    NUMBER OF "TOTAL_MANPOWER."

    NUMBER OF "MTD_TOTAL_ANP."

    NUMBER OF "MTD_PRODUCTIVITY."

    VARCHAR2 (20 CHAR) "YTD_TOTAL_ANP."

    VARCHAR2 (20 CHAR) "YTD_PRODUCTIVITY."

    "ROW_ID" VARCHAR2 (20 BYTE)

    )

    SAMPLE DATA FOR ABM_PRODUCTIVITY

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (104,1,85000, null, '40000', null, ' 6');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (102,1,35000, null, '33000', null, ' 7');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (110,1,25000, null, '25000', null, ' 8');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (116,1,22000, null, '34000', null, ' 10');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (109,1,75000, null, '80000', null, ' 2');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (111,1,25000, null, '25000', null, ' 3');

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (100,1,23000, null, ' 34500', null, "11");

    Insert into ABM_PRODUCTIVITY (AGENT_ID, TOTAL_MANPOWER, MTD_TOTAL_ANP, MTD_PRODUCTIVITY, YTD_TOTAL_ANP, YTD_PRODUCTIVITY, ROW_ID) values (115,1,24000, null, '45000', null, ' 9');

    The output after having received the request and not as my are expected as below: -.

    The result I have espect is as below: -.

    If all goes well, there is a way to solve my question.

    Thank you all and have a nice day

    Hello

    I still don't know how you want to trunking.  You want someone who has a tank of 'AGENT' that lie with its parent in the hierarchy?

    If Yes, you can do the update ROLLUP before you make the CONNECT BY query and claim that summaries are the children of one of the actual lines in the tree, like this:

    WITH got_grp_id AS

    (

    SELECT b.SID, a.upline

    TO_CHAR (a.agent_id) AS a_agent_id

    CASE

    WHEN a.agent_rank = "AGENT".

    AND a.upline IS NOT NULL

    THEN a.upline

    Of OTHER TO_CHAR (a.agent_id)

    END AS grp_id

    p.total_manpower, p.mtd_total_anp

    Of abm_agent_test one

    abm_productivity p

    WHERE a.agent_id = p.agent_id

    )

    got_aggregates AS

    (

    SELECT THE CHECK BOX

    WHEN you GROUP (name) = 0

    THEN the name

    WHEN you GROUP (grp_id) = 0

    THEN "SUBTOTAL".

    ANOTHER "GRAND TOTAL".

    END AS name_s

    CASE

    WHEN you GROUP (upstream) = 0

    THEN upstream

    WHEN you GROUP (grp_id) = 1

    THEN TO_CHAR (: a).

    Of OTHER LAST_VALUE (a_agent_id IGNORE NULLS)

    COURSES (PARTITION BY grp_id

    ORDER OF CASES

    WHEN a_agent_id <> grp_id

    THEN SUM (mtd_total_anp)

    END NULLS FIRST

    ROWS BETWEEN UNBOUNDED PRECEDING

    AND UNBOUNDED FOLLOWING

    )

    END AS parent

    a_agent_id, grp_id

    SUM (total_manpower) AS sum_total_manpower

    SUM (mtd_total_anp) AS sum_mtd_total_anp

    Group of (name) AS g_name

    GROUPING (grp_id) AS g_grp_id

    OF got_grp_id

    GROUP OF ROLLUP (grp_id

    , (name, upstream, a_agent_id)

    )

    )

    SELECT THE CHECK BOX

    WHEN g_grp_id = 0

    THEN LPAD (' ', 4 * (LEVEL - 1))

    END | name_s AS first_nameq

    sum_total_manpower

    sum_mtd_total_anp

    CASE

    WHEN g_name = 0

    THEN THE LEVEL

    4 SOMETHING ELSE

    END as lvl

    a_agent_id

    OF got_aggregates

    START WITH a_agent_id = TO_CHAR (: a).

    Parent = a_agent_id PRIOR CONNECTION

    Brothers and SŒURS of ORDER BY sum_mtd_total_anp

    ;

    Output:

    SUM_

    SUM_ MTD_ A_

    TOTAL_ AGENT TOTAL

    FIRST_NAMEQ MANPOWER _ANP LVL _ID

    -------------------- -------- -------- ---------- -----

    Lily 1 22000 1 116

    Kevin 1 24000 2 115

    PARTIAL TOTAL 2 46000 4

    Sarah 1 25000 2 110

    May 1 85000 3 104

    PARTIAL TOTAL 2 110000 4

    Tom 1 35000 2 102

    John 1 23000 3 100

    Sue 1 25000 3 111

    Salwa 1 75000 3 109

    PARTIAL TOTAL 4 158000 4

    GRAND TOTAL 8 314000 4

    I changed the column names.  (For example, there is a built-in function called RANK, so this isn't a column name good.  "It's confusing to use upstream to 2 unrealted stuff.)

    I guess just what you want for the LVL column.

    Why is agent_id a NUMBER, but upstream a VARCHAR2?  I expect to be of the same data type, so that upstream may be a foreign key referencing agent_id.

  • Grouping data with dates of Max and Min problem

    Ladies and gentlemen,

    I have a problem that I have tried from different angles. It's probably very easy for some of you, or some of you may have met before, so any help on this is greatly appreciated. I will describe below.

    I have the following data:

    User station site code dstamp ref Qty
    -------- --------- ---------- ------------- --------------------------------------------- ------- -------
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.43.06.566193000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.49.31.364224000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.49.47.413252000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.51.48.906793000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.51.56.947312000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.54.29.396052000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.54.37.444307000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.57.00.237546000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.57.04.285148000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.59.24.745162000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.59.44.774318000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 14.01.22.434940000 ref_1 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 14.01.51.291059000 ref_1 1125
    Site_1 user_1 RPT104 Activity_2 16 May 11 14.05.23.572211000 ref_2 1125
    Site_1 user_1 RPT104 Activity_1 16 May 11 14.06.01.058978000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.41.341612000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.375972000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.388699000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.401287000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.413361000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.425675000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.437360000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.449079000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.460697000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.472606000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.484031000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.495551000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.513645000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 16 May 11 14.06.49.530405000 ref_1 1125


    and I'm looking for it in this format:


    Site user station code start end ref Qty
    --------     ---------     ----------     -------------     ---------------------------------------------     ---------------------------------------------          ----------     -------
    Site_1 user_1 RPT104 Activity_1 13.43.06.566193000 16 May 11 May 16, 11 14.05.23.572211000 ref_1 1125
    Site_1 user_1 RPT104 Activity_2 14.05.23.572211000 16 May 11 May 16, 11 14.06.01.058978000 ref_2 1125
    Site_1 user_1 RPT104 Activity_1 14.06.01.058978000 16 May 11 May 16, 11 14.06.41.341612000 ref_1 1125
    Site_1 user_1 RPT104 Activity_3 14.06.41.341612000 16 May 11 (May 16, 11 14.06.49.530405000 + 4secs ref_1 1125)
    either may 16, 11 14.06.53.530405000)


    I can get the hours start and end without problem using data intial twice and it compensation by a rownum is but using the functions max and min based on the data that I get:

    Site user station code start end ref Qty
    --------     ---------     ----------     -------------     ---------------------------------------------     ---------------------------------------------          ----------     -------
    Site_1 user_1 RPT104 Activity_1 16 May 11 13.43.06.566193000 * May 16, 11 14.06.41.341612000 * ref_1 1125
    Site_1 user_1 RPT104 Activity_2 14.05.23.572211000 16 May 11 May 16, 11 14.06.01.058978000 ref_2 1125
    Site_1 user_1 RPT104 Activity_3 * 14.06.41.341612000 * 16 May 11 (May 16, 11 14.06.49.530405000 + 4secs ref_1 1125)
    either may 16, 11 14.06.53.530405000)

    who is missing on the 3rd line of the previous dataset (if everything goes well in fat after validation) and assigns the wrong time end.

    I think the solution may have soemthing to do using the function dense_rank() (any ORDER by code, start) but I'm not too familiar with it and I think that the facts in the Start column data is unique it affects its functioning.

    If anyone can offer any help or point me in the right direction I'll offer eternal grace and rest a drink we should never meet!

    see you soon

    Published by: MickyMick on June 7, 2011 03:21

    BobLilly wrote:
    Tabibitosan of Aketi method can be applied here (see {: identifier of the thread = 1005478})

    Site_1 user_1 RPT104 Activity_1 2011-05-16 13.43.06.566193000 2011-05-16 14.05.23.572211000 ref_1 1125
    Site_1 user_1 RPT104 Activity_2 2011-05-16 14.05.23.572211000 2011-05-16 14.06.01.058978000 ref_2 1125
    Site_1 user_1 RPT104 Activity_1 2011-05-16 14.06.01.058978000 2011-05-16 14.06.41.341612000 ref_1 1125
    Site_1 RPT104 Activity_3 2011-05-16 14.06.41.341612000 user_1 ref_1 14.06.45.341612000 2011-05-16 1125

    According to OP we may 16, 11 14.06.49.530405000 + 4secs. In any case, use method start_of_group:

    With t as (
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.43.06.566193000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.49.31.364224000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.49.47.413252000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.51.48.906793000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.51.56.947312000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.54.29.396052000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.54.37.444307000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.57.00.237546000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.57.04.285148000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.59.24.745162000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 13.59.44.774318000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 14.01.22.434940000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 14.01.51.291059000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_2' as Code
    , to_timestamp('16-MAY-11 14.05.23.572211000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_2' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_1' as Code
    , to_timestamp('16-MAY-11 14.06.01.058978000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.41.341612000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.375972000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.388699000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.401287000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.413361000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.425675000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.437360000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.449079000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.460697000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.472606000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.484031000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.495551000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.513645000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual union all
    Select 'Site_1' as Site, 'user_1' as Usr, 'RPT104' as Station, 'Activity_3' as Code
    , to_timestamp('16-MAY-11 14.06.49.530405000', 'DD-MON-RR HH24:MI:SS.FF') as DTStamp, 'ref_1' as Ref, 1125 as Qty from dual
    ),
    t1 as (
           select  t.*,
                   lead(DTStamp,1,DTStamp + interval '4' second) over(order by DTStamp) ENDTS,
                   case
                     when     lag(Site) over(order by DTStamp)  = Site
                          and
                              lag(Usr) over(order by DTStamp)  = Usr
                          and
                              lag(Station) over(order by DTStamp)  = Station
                          and
                              lag(Code) over(order by DTStamp)  = Code
                          and
                              lag(Ref) over(order by DTStamp)  = Ref
                          and
                              lag(Qty) over(order by DTStamp)  = Qty
                       then 0
                     else 1
                   end start_of_group
             from  t
          ),
    t2 as (
           select  t1.*,
                   sum(start_of_group) over(order by DTStamp) grp
             from  t1
          )
    select  Site,
            Usr,
            Station,
            Code,
            min(DTStamp) STARTTS,
            max(ENDTS) ENDTS,
            Ref,
            Qty
      from  t2
      group by grp,
               Site,
               Usr,
               Station,
               Code,
               Ref,
               Qty
      order by STARTTS
    /
    
    SITE   USR    STATIO CODE       STARTTS                             ENDTS                               REF          QTY
    ------ ------ ------ ---------- ----------------------------------- ----------------------------------- ----- ----------
    Site_1 user_1 RPT104 Activity_1 16-MAY-11 01.43.06.566193000 PM     16-MAY-11 02.05.23.572211000 PM     ref_1       1125
    Site_1 user_1 RPT104 Activity_2 16-MAY-11 02.05.23.572211000 PM     16-MAY-11 02.06.01.058978000 PM     ref_2       1125
    Site_1 user_1 RPT104 Activity_1 16-MAY-11 02.06.01.058978000 PM     16-MAY-11 02.06.41.341612000 PM     ref_1       1125
    Site_1 user_1 RPT104 Activity_3 16-MAY-11 02.06.41.341612000 PM     16-MAY-11 02.06.53.530405000 PM     ref_1       1125
    
    SQL> 
    

    SY.

  • Help on report with max and group of?

    Hello I need to display the next report

    SELECT THE TABLE TABLE_NAME, NOM_PARTITION, LAST_ANALYZED IN USER_TAB_PARTITIONS;
    However, I need to display the table table_name time with sound (partition_name) MAX current (assuming that the names are P2010, P2011, etc...) and when he was last_analyzed

    What is the most effective way to do it? Subselect statement? Inner join?

    Thank you!

    Hello

    Using a GROUP BY:

    SELECT table_name,
           max(partition_name) as partition_name,
           max(last_analyzed) keep (dense_rank last order by partition_name) as last_analyzed
    FROM all_tab_partitions
    GROUP BY table_name
    ;
    

    Another solution would be a TOP - n query, using the ROW_NUMBER analytic function:

    SELECT table_name, partition_name, last_analyzed
    FROM (
      SELECT table_name,
             partition_name,
             last_analyzed ,
             row_number() over( partition by table_name
                                order by nlssort(partition_name,'NLS_SORT=BINARY') desc ) as rn
      FROM all_tab_partitions
    )
    WHERE rn = 1
    ;
    

    Note that I had to use the NLSSORT function to get the same result as the value that the query GROUP BY.
    Depending on your NLS DB/SESSION settings, you may not do.

    Edited by: odie_63 Feb 4. 2011 14:31

  • 7054 TDS query max and min measure

    I seem to have difficulty querying for minimum and maximum measurements on my o'scope 7054 TDS. I have two meaurements on and if I question MEASU:MEAS1:TYP? He returned to MAX and back MIN for MEAS2. Yet, when I try to question the real value MEASU:MEAS1:MAX? It returns 99.000 + 36, which of course cannot be true. The strange thing is that the code works for the DPO4104. No idea what I am doing wrong? I have attached 2 sets of code, 1, that's how I activate measures on the scope, the other tries to query for max and min.

    You must use ": MEASU:MEAS %dto?" to get your data (put the number in the %d).  You ask in fact that the max best scope value recorded.  It can keep some statistics on measures.  Here are the commands that I use to get the data (even once, replace %d by the number of measure):

    : %D MEASU:MEAS: DAT?
    : MEASU:MEAS %d: UNI?

    The first order requested the actual data of the measure as well as the second units of measurement.

  • Uninstall IE and set another web browser such as Chrome and FireFox by default by using Group Policy

    Hello

    Please someone can instruct me on how to uninstall IE and set another web browser such as Chrome and FireFox by default by using Group Policy. Your help would be much appreciated.

    Kind regards

    RocknRollTim

    Hi Tim,.

     

    Thanks for posting your query in Microsoft Community.

    I wish to inform you that, group policy can only be changed if you are using Windows 7 Professional on your computer.

     
    Referring to your other posts, I see that your computers are on a domain network, we have a specific forum for the computers in the domain and they are experts in this field of investigation and would be in a better position to address the concerns. So refer to the link below and post your query on the TechNet Forums.
     
    Hope this information helps, just answer for all the help on Windows.
  • Activate the user audit logs and hide the other audit logs account system on computers in a domain by using Group Policy

    Hello

    Please could someone advise me on how to activate the user audit logs and hide the other audit logs account system on computers in a domain by using Group Policy. Your help would be much appreciated.

    Kind regards

    RocknRollTim

    Hello

    Please contact Microsoft Community.

    We have a specific forum for the computers in the domain and they are experts in this field of investigation and would be in a better position to address the concerns. So refer to the link below and post your query on the TechNet Forums.

    https://social.technet.Microsoft.com/forums/en-us/home

    I hope this helps. If you have any questions on Windows, please answer. We will be happy to help you.

  • Combine results of 2 motions, one of them using Group by and a WITH statement

    Hello world

    I am trying to find a way to combine the results of 2 queries (Oracle 11 g). The first query was a select simple, something like:

    SELECT A.ACTDAT, A.ENDDAT, A.ITMCOD, B.ITMDSC, A.PRDORD, A.FPQTY, A.FPACT
    FROM Table1 A, Table2 B WHERE A.ITMCOD=B.ITMCOD AND A.VERNUM='VM10' ORDER BY A.PRDORD;
    

    The second query is not so "simple", but:

    WITH Tab1 (ProdOrd,Pdate)
          AS (SELECT T.PRDORD, TO_CHAR(T.SYSDAT, 'MM-DD-RR HH24:MI') FROM Table3 T,
    Table4 I, Table5 D, Table6 E
    WHERE I.ITMCLS = D.ITMCLS AND I.ITMCOD = D.ITMCOD
    AND D.DTLTYP = 'F' AND D.TRNSEQ = T.TRNSEQ
    AND T.TRNTYP = 'LINTAK'
    AND D.LOCATN = '10'
    AND E.PRDORD IN (SELECT PRDORD FROM PRDQUE WHERE VERNUM='VM10') 
    )
    SELECT MIN(Pdate) "1er LINTAK", MAX(Pdate) "Ult. LINTAK" FROM Tab1
    GROUP BY ProdOrd
    ORDER BY ProdOrd;
    

    For each A.PRDORD in #1 query, the second query should return the

    MIN(Pdate)
    

    and

    MAX(Pdate)
    

    as follows:

    A.ACDAT (from #1 query) A.ENDAT (from #1 query) A.ITMCOD (from #1 query) B.ITMDSC (from #1 query) A.PRDORD (from #1 query) A.FPQTY (from #1 query) A.FPACT (from #1 query) Min (pdate) (from query #2) Max (pdate) (from query #2)
    02/04/2014-06:0002/04/2014 08:59:43XXYYZZDescription of XXYYZZ00090001770854359702/04/14 06:1702/04/14-09:16

    While separately, both queries return the following results:

    Query #1:


    A.ACDAT (from #1 query) A.ENDAT (from #1 query) A.ITMCOD (from #1 query) B.ITMDSC (from #1 query) A.PRDORD (from #1 query) A.FPQTY (from #1 query) A.FPACT (from #1 query)
    02/04/2014-06:0002/04/2014 08:59:43XXYYZZDescription of XXYYZZ000900017708543597


    Query #2:

    Min (pdate) (from query #2) (pdate) Max (from query #2)
    02/04/14 06:1702/04/14-09:16

    Note: PRDORD in Table1 (query #1) est the same as PRDORD in Table2 (request #2).

    Hope my question is clear enough.

    Any advice or suggestions will be more than welcome!

    Hello

    Post a small example of data (CREATE TABLE and INSERT for all involved tables, the columns only statements) and the results desired from these data.

    See the FAQ forum: https://forums.oracle.com/message/9362002

    You want to include the lines of table2 who lines returned in the other tables.  This sounds like the job for an outer join.

    You want to ignore the dates on some lines.  That wound like a job for a CASE expression (or if-then-else function specialized, like NVL2).

  • the window on my computer does not return to its original size and I can't use the max and min and exit button

    my window is too far to the right and ive tried to get to the original size and it will until a certain point to the left. This leaves me unable to use the max and min and exit tabs

    Hello

    1. What is the brand and model of the computer?

    2. is it a laptop or a desktop computer?

    3. the problem occurs after leaving the game or program?

    4 did you a recent software or changes to the material on the computer?

    Method 1:

    If this happens when you leave a game, I suggest you to follow the steps mentioned in the link and check.

    Open the troubleshooter of display quality

    http://Windows.Microsoft.com/en-us/Windows7/open-the-display-quality-Troubleshooter

    Method 2:

    I also suggest you go through the steps mentioned in the link and the Coachman.

    Change your screen resolution

    http://Windows.Microsoft.com/en-us/Windows7/change-your-screen-resolution

    Method 3:

    Step 1:

    I also suggest you to check if the problem persists in safe mode.

    Start your computer in safe mode

    http://Windows.Microsoft.com/en-us/Windows7/start-your-computer-in-safe-mode

    Step 2:

    You can also check if the problem persists in a clean boot state.

    Clean boot:

    This could happen if one of the substantive programmes is in conflict with the proper functioning of your computer. To help resolve the error and other messages, you can start Windows 7 by using a minimal set of drivers and startup programs. This type of boot is known as a "clean boot". A clean boot helps eliminate software conflicts.

    How to troubleshoot a problem by performing a clean boot in Windows Vista or Windows 7 http://support.microsoft.com/kb/929135

    Note: when you are finished troubleshooting, follow step 7 article to start the computer to a normal startup.

    Hope this helps and keep us posted.

  • Can we use the two Min max and MRP element


    Hello

    We can user Min max and the MRP of planning for the element in the same Org (11.5.10.2)

    Thanks in advance

    Ravi

    Hi Ravi,

    There are no restrictions such as a... but it would be an unnecessary activity.

    If your release to users even planned orders by mistake... you would create duplicate supplies.

    Is there any need specific job for which you want to use both of these methods of planning as a whole?

    Kind regards

    Mohan Balaji

  • Max and min function

    I have a special request, I'm looking for the max and, possibly, of the minutes of the date that the order was made.

    EMP_ID Full_Name Date
    1 Jim Smith 02/01/2011
    1 Jim Smith 13/01/2011
    1 Jim Smith 15/01/2011
    2 Susan Morgan 20/02/2011
    2 Susan Morgan 22/02/2011
    2 Susan Morgan 25/02/2011
    2 Susan Morgan 28/02/2011

    So, if I have 2 tables Emp and joined by say Emp_id orders and I need the elements following result set

    EMP_ID Full_Name Date max (date) min (date)
    1 Jim Smith 1/2/2011 1/15/2011 1/2/2011
    1 Jim Smith 1/13/2011 1/15/2011 1/2/2011
    1 Jim Smith 1/15/2011 1/15/2011 1/2/2011
    2 Susan Morgan 2/20/2011 2/28/2011 2/20/2011
    2 Susan Morgan 2/22/2011 2/28/2011 2/20/2011
    2 Susan Morgan 2/25/2011 2/28/2011 2/20/2011
    2 Susan Morgan 2/28/2011 2/28/2011 2/20/2011


    It is a simplified query that my orginal query has more columns that I have to choose and more tables. I don't know if I can use a select group on because I would have to force all the columns and that would be just grap date unique columns max since I bring together down the line

    Hello

    Oracle_Rookie wrote:
    ... I don't know if I can use a select group on because I would have to force all the columns and that would be just grap date unique columns max since I bring together down the line

    Yes, probably do not want to use GROUP BY. Use more Analytics MIN and MAX fucntions. For example:

    SELECT       deptno
    ,       ename
    ,       hiredate
    ,       MAX (hiredate) OVER (PARTITION BY deptno)     AS last_in_dept
    FROM       scott.emp
    ORDER BY  deptno
    ,            hiredate
    ;
    

    Output:

    `   DEPTNO ENAME      HIREDATE  LAST_IN_D
    ---------- ---------- --------- ---------
            10 CLARK      09-JUN-81 23-JAN-82
            10 KING       17-NOV-81 23-JAN-82
            10 MILLER     23-JAN-82 23-JAN-82
    
            20 SMITH      17-DEC-80 23-MAY-87
            20 JONES      02-APR-81 23-MAY-87
            20 FORD       03-DEC-81 23-MAY-87
            20 SCOTT      19-APR-87 23-MAY-87
            20 ADAMS      23-MAY-87 23-MAY-87
    
            30 ALLEN      20-FEB-81 03-DEC-81
            30 WARD       22-FEB-81 03-DEC-81
            30 BLAKE      01-MAY-81 03-DEC-81
            30 TURNER     08-SEP-81 03-DEC-81
            30 MARTIN     28-SEP-81 03-DEC-81
            30 JAMES      03-DEC-81 03-DEC-81
    

    Most of the aggregates fucntions have analytical counterparts, which can give you the same results without collapsing the entire down to one line per result group. The analytical PARTITION BY clause matches the GROUP BY clause in an aggregate query.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
    Make the sample data as simple as you can, so it has the same problem that occurs in your actual query.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

    Published by: Frank Kulash, March 15, 2011 12:50

  • Query using progressive relaxation take more time for execution

    HI gurus,

    I'm creating a query using the context and the progressive relaxation index

    I had started using progressive relaxation after obtaining the forum entries {: identifier of the thread = 2333942}. With the help of progressive relaxation takes more than 7 seconds for each request. Is there a way we can improve the query performance?
     create table test_sh4 (text1 clob,text2 clob,text3 clob);
    
    begin
       ctx_ddl.create_preference ('nd_mcd', 'multi_column_datastore');
       ctx_ddl.set_attribute
           ('nd_mcd',
            'columns',
            'replace (text1, '' '', '''') nd1,
             text1 text1,
             replace (text2, '' '', '''') nd2,
             text2 text2');
       ctx_ddl.create_preference ('test_lex1', 'basic_lexer');
       ctx_ddl.set_attribute ('test_lex1', 'whitespace', '/\|-_+');
       ctx_ddl.create_section_group ('test_sg', 'basic_section_group');
       ctx_ddl.add_field_section ('test_sg', 'text1', 'text1', true);
       ctx_ddl.add_field_section ('test_sg', 'nd1', 'nd1', true);
       ctx_ddl.add_field_section ('test_sg', 'text2', 'text2', true);
       ctx_ddl.add_field_section ('test_sg', 'nd2', 'nd2', true);
     end;
    
    create index IX_test_sh4 on test_sh4 (text3)   indextype is ctxsys.context   parameters    ('datastore     nd_mcd   lexer test_lex1 section group     test_sg') ;
    
    alter index IX_test_sh4 REBUILD PARAMETERS ('REPLACE SYNC (ON COMMIT)') ;-- sync index on every commit. 
    
    
    SELECT SCORE(1) score,t.* FROM test_sh4 t WHERE CONTAINS (text3,  '
    <query>
    <textquery>
    <progression>
    <seq>{GIFT GRILL STAPLES CARD} within text1</seq>
    <seq>{GIFTGRILLSTAPLESCARD} within nd1</seq>
    <seq>{GIFT GRILL STAPLES CARD} within text2</seq>
    <seq>{GIFTGRILLSTAPLESCARD} within nd2</seq>
    <seq>((%GIFT% and %GRILL% and %STAPLES% and %CARD%)) within text1</seq>
    <seq>((%GIFT% and %GRILL% and %STAPLES% and %CARD%)) within text2</seq>
    <seq>((%GIFT% and %GRILL% and %STAPLES%) or (%GRILL% and %STAPLES% and %CARD%) or (%GIFT% and %STAPLES% and %CARD%) or (%GIFT% and %GRILL% and %CARD%)) within text1</seq>
    <seq>((%GIFT% and %GRILL% and %STAPLES%) or (%GRILL% and %STAPLES% and %CARD%) or (%GIFT% and %STAPLES% and %CARD%) or (%GIFT% and %GRILL% and %CARD%)) within text2</seq>
    <seq>((%STAPLES% and %CARD%) or (%GIFT% and %GRILL%) or (%GRILL% and %CARD%) or (%GIFT% and %CARD%) or (%GIFT% and %STAPLES%) or (%GRILL% and %STAPLES%)) within text1</seq>
    <seq>((%STAPLES% and %CARD%) or (%GIFT% and %GRILL%) or (%GRILL% and %CARD%) or (%GIFT% and %CARD%) or (%GIFT% and %STAPLES%) or (%GRILL% and %STAPLES%)) within text2</seq>
    <seq>((%GIFT% , %GRILL% , %STAPLES% , %CARD%)) within text1</seq>
    <seq>((%GIFT% , %GRILL% , %STAPLES% , %CARD%)) within text2</seq>
    <seq>((!GIFT and !GRILL and !STAPLES and !CARD)) within text1</seq>
    <seq>((!GIFT and !GRILL and !STAPLES and !CARD)) within text2</seq>
    <seq>((!GIFT and !GRILL and !STAPLES) or (!GRILL and !STAPLES and !CARD) or (!GIFT and !STAPLES and !CARD) or (!GIFT and !GRILL and !CARD)) within text1</seq>
    <seq>((!GIFT and !GRILL and !STAPLES) or (!GRILL and !STAPLES and !CARD) or (!GIFT and !STAPLES and !CARD) or (!GIFT and !GRILL and !CARD)) within text2</seq>
    <seq>((!STAPLES and !CARD) or (!GIFT and !GRILL) or (!GRILL and !CARD) or (!GIFT and !CARD) or (!GIFT and !STAPLES) or (!GRILL and !STAPLES)) within text1</seq>
    <seq>((!STAPLES and !CARD) or (!GIFT and !GRILL) or (!GRILL and !CARD) or (!GIFT and !CARD) or (!GIFT and !STAPLES) or (!GRILL and !STAPLES)) within text2</seq>
    <seq>((!GIFT , !GRILL , !STAPLES , !CARD)) within text1</seq>
    <seq>((!GIFT , !GRILL , !STAPLES , !CARD)) within text2</seq>
    <seq>((?GIFT and ?GRILL and ?STAPLES and ?CARD)) within text1</seq>
    <seq>((?GIFT and ?GRILL and ?STAPLES and ?CARD)) within text2</seq>
    <seq>((?GIFT and ?GRILL and ?STAPLES) or (?GRILL and ?STAPLES and ?CARD) or (?GIFT and ?STAPLES and ?CARD) or (?GIFT and ?GRILL and ?CARD)) within text1</seq>
    <seq>((?GIFT and ?GRILL and ?STAPLES) or (?GRILL and ?STAPLES and ?CARD) or (?GIFT and ?STAPLES and ?CARD) or (?GIFT and ?GRILL and ?CARD)) within text2</seq>
    <seq>((?STAPLES and ?CARD) or (?GIFT and ?GRILL) or (?GRILL and ?CARD) or (?GIFT and ?CARD) or (?GIFT and ?STAPLES) or (?GRILL and ?STAPLES)) within text1</seq>
    <seq>((?STAPLES and ?CARD) or (?GIFT and ?GRILL) or (?GRILL and ?CARD) or (?GIFT and ?CARD) or (?GIFT and ?STAPLES) or (?GRILL and ?STAPLES)) within text2</seq>
    <seq>((?GIFT , ?GRILL , ?STAPLES , ?CARD)) within text1</seq>
    <seq>((?GIFT , ?GRILL , ?STAPLES , ?CARD)) within text2</seq>
    </progression>
    </textquery>
    <score datatype="FLOAT" algorithm="default"/>
    </query>',1) >0 ORDER BY score(1) DESC

    Progressive relaxation works best when you select only a limited number of lines. If you retrieve ALL the rows that satisfy the query, then every step of easing should run without worrying.

    If you collect - say - the first 10 results, then if the first step in the relaxation gives 10 results so there is no need to execute the next step (actually, due to the internal buffering, which won't be exactly true but he is theoretically correct).

    The easiest way to proceed is to reformulate the query in the form

    SELECT * FROM)
    (Score select (1) SCORE, t.* FROM test_sh4 t WHERE CONTAINS (Text3, '))


    ...


    (1) > 0 ORDER BY score (1) DESC
    )
    WHERE ROWNUM<=>

    You have discovered that wildcards don't work too well, unless you use SUBSTRING_INDEX. I encourage you to avoid completely if possible, or push down much lower in the progressive relaxation. Usually, GIFT % is a useful term (matches GIFTS, GIFTED, etc.), DON % is generally more effective.

    There are a lot of steps in your progressive relaxation. It you want to reduce the number of steps, you can change:

    ((GIFT and percent of the GRID and STAPLES % and CARD %)) in Text1
    ((GIFT and percent of the GRID and STAPLES % and CARD %)) in Text2

    TO

    ((CADEAU % et % de la GRILLE et AGRAFES % et CARTE %) * 2) within Text1 ACCUM ((GIFT and percent of the GRID and STAPLES % and CARD %)) in Text2

    I don't know if it would have performance benefits - but it is worth trying to see.

  • BET MAX and second MAX AMOUNT

    Hello world

    in the EMP table.

    I want to get the MAX and second MAX Salary for the 30 and total Department at line 10 in a Department.

    Like this

    Salary eleve---deuxieme better pay - total dept 10
    2850 1600-8750


    Kind regards

    Mahir M. Quluzade wrote:

    select
    deptno, maxs "Higher Salary", max(sal) "Second higher Salary",sums "total dept"
    from
    (
    
    select
    deptno,sal,
    max(sal) over(partition by deptno) maxs,
    sum(sal) over (partition by deptno) sums
    
    from scott.emp
    WHERE deptno =10)
    where sal != maxs
    group by deptno, maxs, sums
    

    UH... they wanted the highest and 2nd highest of deptno = 30, so it should not be something like this...

    WITH t_sal AS
    (
     SELECT deptno,
            sal,
            ROW_NUMBER() OVER(PARTITION BY deptno ORDER BY sal DESC) rn,
            SUM(sal)     OVER(PARTITION BY deptno ORDER BY deptno) tot
     FROM   emp
    ),   t_data AS
    (
     SELECT deptno,
            sal,
            rn,
            tot
     FROM   t_sal
     WHERE  (rn IN (1,2)
     AND    deptno = 30)
     OR     (rn = 1
     AND    deptno = 10)
    )
    SELECT MAX(CASE WHEN deptno = 30 AND rn = 1 THEN sal ELSE NULL END) higher,
           MAX(CASE WHEN deptno = 30 AND rn = 2 THEN sal ELSE NULL END) second_higher,
           MAX(CASE WHEN deptno = 10 AND rn = 1 THEN tot ELSE NULL END) total_for_10
    FROM   t_data;
    

    ?

    Published by: Munky on February 23, 2011 13:40 - typo

  • Need help with query outputing group names

    I'm trying to find a way for groups of output headers, then all the records in each group etc header. It would be easy, except there is a key with what I want to do.

    Normally, if I have this data set (that I've ' borrowed' a site that showed the closest to what I was looking for):

    Example table:

    TABLE [number]

    (Name, NUMBER)

    Dave Bower 843-444-4444

    Dave Bower 843-555-5555

    Matthew Small 843-111-1111

    Matthew Small _843-222-2222

    Matthew Small 843-333-3333

    I could use the following code:

    < cfoutput query = "somequery" group = "name" >

    #name # < br >

    < cfoutput >

    #phonenumber # < br >

    < / cfoutput >

    < hr >

    < / cfoutput >

    And get this:

    Dave Bower

    843-444-4444.

    843-555-5555.

    -------------------

    Matthew Small

    843-111-1111.

    843-222-2222.

    843-333-3333.

    -------------------

    BUT my actual tables are not set up like that. Rather than recording of every name of every record, I would have an ID that is the foreign key to another table.

    Current table set up is as follows:

    TABLE [people]

    (ID, NAME)

    1 Dave Bower

    2 small Matthew

    TABLE [Phones]

    (PEOPLE_ID NUMBER)

    1 843-444-4444

    1 843-555-5555

    2 843-111-1111

    2 843-222-2222

    2 843-333-3333

    If this output actually would this give me with my current setup and request above code:

    1

    843-444-4444.

    843-555-5555.

    -------------------

    2

    843-111-1111.

    843-222-2222.

    843-333-3333.

    -------------------

    How can I keep my current setup but create a query that produces the same result from the top? (The table names of people like the group headers, but data from the phones table under that output)

    You must gather the two tables, and then group the output.

    Something along the lines of the (may vary slightly depending on your DB and the exact table structure)

    SELECT ppl.name, ph.number

    PEOPLE ppl

    INNER JOIN phones ph ON ppl.id = ph.people_id

    ORDER BY ppl.name

    See you soon

    Kai

  • Separate operation using GROUP BY

    I was researching on the extraction of duplicates in a table.

    create table x
    (empid number,
    empname varchar2(50)
    );
    
    insert into x values (1,'John');
    insert into x values (2,'Reynolds');
    insert into x values (3,'Harrison');
    insert into x values (1,'Kate');
    insert into x values (2,'Hans');
    
    
    SQL> select * from x;
    
         EMPID EMPNAME
    ---------- ------------------------------
             1 John
             2 Reynolds
             3 Harrison
             1 Kate
             2 Hans
             
    
    SQL> select empid from x group by empid;          ------ Query 1
    
         EMPID
    ----------
             1
             2
             3         
             
    SQL> select min(empid) from x group by empid;      ------ Query 2
    
    MIN(EMPID)
    ----------
             1
             2
             3
    
    
    SQL> select * from x where empid not in
      2  (select min(empid) from x group by empid);   -------- Query 3    
    
    no rows selected
    I understand how the query 1 and query 2 retrieves distinct values. Query 3 impossible to extract values duplicate because it is equivalent to
    SQL> select * from x where empid not in
      2  (select distinct(empid) from x);
    
    no rows selected
    Am I wrong?

    From different threads OTN, I gathered that a query using ROWID should be used to extract duplicate rows.
    Something like
    select * from x where rowid not in
    (select min(rowid) from x group by empid);   ------------- Query 4
    How to work with this query (query 4) and 3 of the application does not work?

    Hello

    Y.Ramlet wrote:
    I was researching on the extraction of duplicates in a table.

    create table x
    (empid number,
    empname varchar2(50)
    );
    
    insert into x values (1,'John');
    insert into x values (2,'Reynolds');
    insert into x values (3,'Harrison');
    insert into x values (1,'Kate');
    insert into x values (2,'Hans');
    
    SQL> select * from x;
    
    EMPID EMPNAME
    ---------- ------------------------------
    1 John
    2 Reynolds
    3 Harrison
    1 Kate
    2 Hans
    
    SQL> select empid from x group by empid;          ------ Query 1
    
    EMPID
    ----------
    1
    2
    3         
    
    SQL> select min(empid) from x group by empid;      ------ Query 2
    
    MIN(EMPID)
    ----------
    1
    2
    3
    
    SQL> select * from x where empid not in
    2  (select min(empid) from x group by empid);   -------- Query 3    
    
    no rows selected
    

    I understand how the query 1 and query 2 retrieves distinct values. Query 3 impossible to extract values duplicate because it is equivalent to

    SQL> select * from x where empid not in
    2  (select distinct(empid) from x);
    
    no rows selected
    

    Am I wrong?

    Yes, you're right. 3 and 4 of the query request to get the same results (or lack of results) in different ways.

    From different threads OTN, I gathered that a query using ROWID should be used to extract duplicate rows.
    Something like

    select * from x where rowid not in
    (select min(rowid) from x group by empid);   ------------- Query 4
    

    How to work with this query (query 4) and 3 of the application does not work?

    They both work. they get different results because they are different things.
    ROWID is unique; EmpID is not. When you "GROUP BY empid", no matter what group with more than one Member will have ROWID that is not equal to MIN (ROWID) for this group.

Maybe you are looking for