Using the query to get the group by rollup subtotal
Hello
Expected output is, for 'chris' each record must have subtotal row because it has different 'no' of the column values.
For 'John' the subtotal came as planned because she didn't even.
Could you please correct the query for "chris" below!
select case when nm is null then 'Total' when no is null then 'Subtotal' else nm end nm,no,emplmt,profund,status,dt,sal,days,intrst,intrs1,intrs2 from ( with t as (select 'chris' nm , 10 no ,'FT' Emplmt, 'PF' ProFund , 'Reg' Status ,to_Date ('01/22/2014','mm/dd/yyyy') dt , 2456 sal, 10 days , 50 intrst ,55 intrs1 ,60 intrs2 from dual union all select 'chris' nm , 20 no ,'FT' Emplmt, 'PF' ProFund , 'Reg' Status ,to_Date ('01/03/2014','mm/dd/yyyy') dt , 1000 sal, 30 days , 50 intrst ,55 intrs1 ,60 intrs2 from dual union all select 'chris' nm , 30 no ,'FT' Emplmt, 'PF' ProFund , 'NonReg' Status ,to_Date ('01/01/2014','mm/dd/yyyy') dt , 20 sal, -5 days , 1 intrst ,1 intrs1 ,1 intrs2 from dual union all select 'john' nm , 11 no ,'PT' Emplmt, 'PF' ProFund , 'Reg' Status ,to_Date ('05/02/2014','mm/dd/yyyy') dt , 1153 sal, 10 days , 50 intrst ,55 intrs1 ,60 intrs2 from dual union all select 'john' nm , 11 no ,'PT' Emplmt, 'PF' ProFund , 'Reg' Status ,to_Date ('05/16/2014','mm/dd/yyyy') dt , 1000 sal, 8 days , 40 intrst ,45 intrs1 ,50 intrs2 from dual ) select nm,no,emplmt,profund,status,dt,sum(sal)sal,sum(days)days,sum(intrst)intrst,sum(intrs1)intrs1,sum(intrs2)intrs2 from t GROUP BY ROLLUP (nm,no,emplmt,profund,status,dt) order by nm,no,emplmt,profund,status,dt ) where (no is not null and emplmt is not null and profund is not null and status is not null and dt is not null) or (no is null and emplmt is null and profund is null and status is null and dt is null)
allows us to use grouping sets to produce just the totals you want.
with t as
(select "chris" nm1, 10 no1, "Pi" Emplmt, "PF" ProFund "Reg" Status, to_Date (January 22, 2014 "," mm/dd/yyyy") dt, 2456 sal, 10 days, 50 intrst, intrs1 55 intrs2 60 double)
Union of all the
Select No, the "chris" nm, 20 'ft' Emplmt, "PF" ProFund "Reg" Status, to_Date (3 January 2014 "," mm/dd/yyyy") dt, intrst 50, intrs1 55, 1000 sal, 30 days, 60 intrs2 of the double
Union of all the
Select "chris" nm, 30 no, "Pi" Emplmt, ProFund "PF", "NonReg" State, to_Date (January 1, 2014 "," mm/dd/yyyy") dt, 20 sal,-5 days, 1 intrst, 1 intrs1, 1 intrs2 of the double
Union of all the
Select "Jean" nm, 11 no, "PT" Emplmt, "PF" ProFund "Reg" Status, to_Date (May 2, 2014 "," mm/dd/yyyy") dt, 1153 sal, 10 days, 50 intrst, intrs1 55 intrs2 60 double
Union of all the
Select "Jean" nm, 11 no, "PT" Emplmt, "PF" ProFund "Reg" Status, to_Date (16 may 2014 "," mm/dd/yyyy") dt, 1000 sal, 8 days, intrst 40, 45 intrs1, 50 intrs2 of the double
)
SELECT
CASE
WHEN grouping (nm1) = 1
THEN "Total".
WHEN grouping (emplmt) = 1
THEN "Subtotal".
Of ANOTHER nm1
END nm,
CASE
WHEN grouping (emplmt) = 1
THEN NULL
Of ANOTHER no1
END no emplmt, profund, status, dt, sal SUM (sal), SUM (days) days, SUM (intrst) intrst, SUM (intrs1) intrs1, intrs2 SUM (intrs2)
T
GROUP BY Grouping SETS ((), (nm1, no1), (nm1, no1, emplmt, profund, status, dt))
ORDER BY nm1, no1, emplmt, profund, status, dt
NM NO EM PR STATUS DT SAL DAYS INTRST INTRS1 INTRS2 chris 10 FT PF Reg 22.01.14 2456 10 50 55 60 Subtotal 2456 10 50 55 60chris 20 FT PF Reg 03.01.14 1000 30 50 55 60 Subtotal 1000 30 50 55 60chris 30 FT PF NonReg 01.01.14 20 -5 1 1 1 Subtotal 20 -5 1 1 1john 11 PT PF Reg 02.05.14 1153 10 50 55 60 john 11 PT PF Reg 16.05.14 1000 8 40 45 50Subtotal 2153 18 90 100 110 Total 5629 53 191 211 231
Tags: Database
Similar Questions
-
Error when you use the Group feature
Oracle forms6i
Hai
While I compile my coding it will compile correctly, but when I tried to run I revealed an error in the function of group
my code is
If (NTC <>0) then
Select the BAR code, RESPONDENT, OUTTIME today_bar, today_in, today_out from dail_att where BARCODE =: bar code
and ATTEND_DATE =: bardate;
Update dail_att set outtime = max(:bartime) where barcode =: bar code
and ATTEND_DATE =: bardate;
on the other
If (cnt2 <>0) then
Select RESPONDENT, OUTTIME in yest_in, yest_out from dail_att where BARCODE =: bar code
and ATTEND_DATE =: bardate-1;
If (yest_in is not null and yest_out is null) then
Update dail_att set outtime = max(:bartime) where barcode =: bar code
and ATTEND_DATE =: bardate-1;
on the other
insert into dail_att(barcode,intime,attend_date)
values (: Barcode, min(:Bartime),: bardate);
end if;
on the other
If: bartime between 0100 and 0630
insert into dail_att(barcode,intime,attend_date)
values (: Barcode, min(:Bartime),: bardate-1);
Update dail_att set outtime = max(:bartime) where barcode =: bar code
and ATTEND_DATE =: bardate-1;
on the other
insert into dail_att(barcode,intime,attend_date)
values (: Barcode,: min (Bartime),: bardate);
end if;
end if;
end if;
while I'm trying this groupfunction it throws error while I use seen tell me how to use the Group feature and where
to use
Regadrs
Srikkanth.MSrikkanth,
For this you need to calculate the max outside of the update statement and then use this value in the update statement.
The bartime is a control in the block?
If Yes, then you need to find the max manually, and if it isn't, then you can write a sub query to find the maximum value.
Kind regards
Manu.
If my response or response from another person was helpful, please mark accordingly
-
using the group name and password group in client anyconnect
Hello. Is it possible to use the group name/password of the legacy in customer cisco anyconnect vpn client? I checked the AnyConnect Administrator's Guide ' VPN XML Reference"and found nothing on this subject.
It's true.
AnyConnect Secure Mobility Client (VPN Module) can be used to connect to both types of VPN remote access:
1. full SSL VPN tunnel
2 IKEv2 VPN IPsec.
The legacy VPN client is used only with the old IKEv1 IPsec VPN and you cannot use this type of VPN client AnyConnect.
-
How to use the Group feature in insert or update
Hai All
How to use the Group feature in insert or update statement
I'm generating attendance so I have a different set of timing example
0800,1200,1230, 1700 and I need to insert data into the table that contains the intimate value min and max value for
outtime and othere to inertval time in or out
Pls tell me with some examples
For example
For INSERT
Insert into T2 (barcode, empcode, respondent, attend_date)
values (R2.cardn, R2.enpno, min(R2.) PtIMe), R2.pdate);
Update
Update dail_att set outtime = MAX (r2.ptime) where empcode = r2.enpno and barcode = r2.cardn and
attend_date = r2.pdate;
Here, in the place where I used to have so pls tell how to use
Thanks and greetings
Srikkanth.MHi Srikkanth.M
to insert:
insert into test (dummy) values ((select max (dummy) to double));
Update:
Update test dummy value = (select max (dummy) to double where to test them. XXXXField = double. XXXXField);
-
How to use the Group condition in the ODI mappings
Hi Experts,
I have a requirement in the customization of BI applications. Can you please someone explain how to use the LISTAGG function in odi mapping.
I applied the LISTAGGR function at the level of mapping odi, but I get error below.
Mapping of ODI: ColumnName: ENAME Expression: LISTAGG (EMP. ENAME, ",") THE GROUP (RANKING BY EMP. ENAME)
Error:
ODI-1240: Flow LIST_AGG_FUN_USAGE fails during an operation of integration. This flow of charge table target EMP_BI.
ODI-1228: task failed LIST_AGG_FUN_USAGE (integration) on the scott_db of ORACLE target connection.
Caused by: java.sql.SQLSyntaxErrorException: ORA-00937: not a function of simple-group
Oracle query:
If I used this sql query in the database the correct result is.
SELECT DEPTNO, LISTAGG (ENAME, ',') WITHIN THE EMP EMP (ENAME CONTROL) GROUP. DEPTNO;
Output:
10 CLARK, KING, MILLER 20 ADAMS, FORD, JONES, SCOTT, SMITH 30 ALLEN, JAMES, MARTIN, BLAKE, TURNER, WARD Please give your valid solutions, thanks in advance.
Kind regards
REDA
If you try in #ODI12C then in the set of properties, you can select the column which should be used to group by.
If it's 11g so its bit complicated. Simply replace the mapping with below codes.
LISTAGG (EMP. ENAME, ",") WITHIN GROUP (ORDER BY ENAME) / * sum() * /.
Magic!
Thank you
Chantal
-
Needing a maximum date using the group value of
I need a join_date of date value maximum for each Department. If max (join_date) has two records for each dept max (end_date) are to be considered. I used a select queryCreate table student (dept number(10), dep_name varchar2(10),join_date date,years_attended number(10),end_date date); insert into student values (1,'I',to_date('3/7/1917','MM/DD/YYYY'),4,to_date('8/26/1987','MM/DD/YYYY')); insert into student values (1,'I',to_date('1/1/1900','MM/DD/YYYY'),4,to_date('8/26/1932','MM/DD/YYYY')); insert into student values (1,'D',to_date('1/1/1920','MM/DD/YYYY'),5,to_date('8/26/1994','MM/DD/YYYY')); insert into student values (1,'C',to_date('1/1/1920','MM/DD/YYYY'),6,to_date('8/26/1945','MM/DD/YYYY')); insert into student values (2,'I',to_date('7/1/1900','MM/DD/YYYY'),3,to_date('8/26/1932','MM/DD/YYYY')); insert into student values (2,'I',to_date('8/16/1916','MM/DD/YYYY'),9,to_date('8/26/1923','MM/DD/YYYY')); insert into student values (2,'D',to_date('8/16/1916','MM/DD/YYYY'),10,to_date('8/26/1987','MM/DD/YYYY')); insert into student values (3,'I',to_date('3/7/1917','MM/DD/YYYY'),4,to_date('8/26/1987','MM/DD/YYYY')); insert into student values (3,'D',to_date('7/28/1920','MM/DD/YYYY'),6,to_date('8/26/1945','MM/DD/YYYY')); insert into student values (3,'I',to_date('7/28/1920','MM/DD/YYYY'),8,to_date('8/26/1965','MM/DD/YYYY')); insert into student values (4,'I',to_date('12/31/1924','MM/DD/YYYY'),2,to_date('8/26/1998','MM/DD/YYYY')); insert into student values (4,'I',to_date('6/10/1929','MM/DD/YYYY'),1,to_date('8/26/1943','MM/DD/YYYY')); insert into student values (4,'C',to_date('1/17/1927','MM/DD/YYYY'),4,to_date('8/26/1955','MM/DD/YYYY')); insert into student values (4,'C',to_date('6/10/1929','MM/DD/YYYY'),30,to_date('8/26/1967','MM/DD/YYYY')); insert into student values (5,'D',to_date('2/10/1931','MM/DD/YYYY'),2,to_date('8/26/1943','MM/DD/YYYY')); insert into student values (5,'I',to_date('2/10/1931','MM/DD/YYYY'),24,to_date('8/26/1962','MM/DD/YYYY')); commit;
gives me the following resultselect * from student where join_date in (select max(join_date) from student group by dept);
But I'm looking for the result that gives me only a maximum value for each column dept. First of all, it should look like to a maximum value of join_date, so two records even join_date max (end_date) are to be considered. The result should be sumthing like this1 D 1/1/1920 5 8/26/1994 1 C 1/1/1920 6 8/26/1945 2 I 8/16/1916 9 8/26/1923 2 D 8/16/1916 10 8/26/1987 3 D 7/28/1920 6 8/26/1945 3 I 7/28/1920 8 8/26/1965 4 I 6/10/1929 1 8/26/1943 4 C 6/10/1929 30 8/26/1967 5 D 2/10/1931 2 8/26/1943 5 I 2/10/1931 24 8/26/1962
Can you please tell me how to rewrite the select query for results above.1 D 1/1/1920 5 8/26/1994 2 D 8/16/1916 10 8/26/1987 3 I 7/28/1920 8 8/26/1965 4 C 6/10/1929 30 8/26/1967 5 I 2/10/1931 24 8/26/1962
Published by: user11872870 on August 2, 2011 17:29
Published by: user11872870 on August 2, 2011 17:36Hello
This is called a Query Top - N , and this is a way to do it:
WITH got_r_num AS ( SELECT student.* , ROW_NUMBER () OVER ( PARTITION BY dept ORDER BY join_date DESC , end_date DESC ) AS r_num FROM student ) SELECT dept, dep_name, join_date, years_attended, end_date FROM got_r_num WHERE r_num = 1 ORDER BY dept ;
Another way is similar to what you posted:
SELECT * FROM student WHERE (dept, join_date, end_date) IN ( SELECT dept , MAX (join_date) , MAX (end_date) KEEP (DENSE_RANK LAST ORDER BY join_date) FROM student GROUP BY dept );
I suspect that the first way (using ROW_NUMBER) will be faster.
In addition, the ROW_NUMBER approach is guaranteed to return only 1 line by Department using the approach of GROUP BY, if there is a link on join_date and end_date then it will return all the contenders in this Department. using ROW_NUMBER, it is easy to add expressions to tie-break as much as you want, and, if there is still a tie, it will be arbirarily pick, one lines involved in the tie as #1.Thanks for posting the CREATE TABLE and INSERT! It is very useful.
Published by: Frank Kulash, August 2, 2011 21:00
Added GROUP BY alternative -
SDO_RELATE slow when you use the Group of... Help, please!
Hi all
I'm pretty new on the space side of Oracle please go easy on me.
I have 2 tables (a and b), each containing line geometries. There is a one (a) to many (b) relationship between the two.
I want to write a query that selects the information of table b where geometries in table b are fully covered by the geometries in the table has, but the return info is grouped by rows in table a.
Here is my code:
Select
a.Route_ID,
a.Step,
Max (b.gritter_status),
Sum (b.salt_usage)
Of
tbl_routedirs a, tbl_routelinks b
where
a.Route_ID = b.route_id and
sdo_covers (a.geoloc, b.geoloc) = 'TRUE '.
Group
a.Route_ID, a.step
The application is extremely slow, taking up to 15 minutes to run... The thing that confuses me is the group by clause of the statement runs in less than half a second.
I checked all the indexes, etc - are all valid. I tried to re - order tables in the clause that ive read it can be a factor and certainly I have little knowledge about what to Exchange where but it seemed to have no impact on speed.
Any suggestions would be warmly welcome... Thank you.
Published by: user8760008 on August 27, 2009 07:08 - I copied the script and do not add functions of aggregation on the selected columns...If this is the case, please try:
Select / * + leading (a) use_nl (a and b) index (your_index_on_b.geoloc b) * /.
a.Route_ID,
a.Step,
Max (b.gritter_status),
Sum (b.salt_usage)
Of
tbl_routedirs a, tbl_routelinks b
where
a.Route_ID = b.route_id and
sdo_coveredby (b.geoloc, a.geoloc) = 'TRUE '.
Group
a.Route_ID, a.stepthat is to have nested loops join, then take a small table as external.
Note that you should not all three tips to get the nested loops join plan. -
How can I put several addressed in a 'group' that I can send using the group name?
I have an address book and you can send an email to several at once by adding each in hand and the cc or BCC fields. As I often do, I need to 'collect' in a group, so I can use the name of the group to send to several people.
_ http://KB.mozillazine.org/Thunderbird: _FAQs_:_Create_Mailing_List
-
query multiple instances of the table min value using the Group of
Hi all
I use Oracle 10.2 on Windows 2003
I'm trying to select the value min for a table, and if there are several occurrences of a value min, the list of all and not just a line. For example, the following query
gives the following resultswith test1 as( select to_date('2009-11-01','YYYY-MM-DD') t_date, 't_1' t_name, '1' t_value from dual union all select to_date('2009-12-01','YYYY-MM-DD') t_date, 't_1' t_name, '2' t_value from dual union all select to_date('2010-01-01','YYYY-MM-DD') t_date, 't_1' t_name, '1' t_value from dual union all select to_date('2010-02-01','YYYY-MM-DD') t_date, 't_1' t_name, '3' t_value from dual union all select to_date('2010-03-01','YYYY-MM-DD') t_date, 't_1' t_name, '4' t_value from dual union all select to_date('2010-04-01','YYYY-MM-DD') t_date, 't_1' t_name, '5' t_value from dual union all select to_date('2010-05-01','YYYY-MM-DD') t_date, 't_1' t_name, '6' t_value from dual union all select to_date('2010-06-01','YYYY-MM-DD') t_date, 't_1' t_name, '1' t_value from dual union all select to_date('2010-07-01','YYYY-MM-DD') t_date, 't_1' t_name, '1' t_value from dual ) select trunc(t_date,'YYYY') t_date, min(t_value) min_value from test1 group by trunc(t_date,'YYYY')
then I looked at the forums and tried the following queryt_date min_value --------- -------------- 01-JAN-09 1 01-JAN-10 1
I get the results you want with this query, which arewith test1 as( select to_date('2009-11-01','YYYY-MM-DD') t_date, 't_1' t_name, '1' t_value from dual union all select to_date('2009-12-01','YYYY-MM-DD') t_date, 't_1' t_name, '2' t_value from dual union all select to_date('2010-01-01','YYYY-MM-DD') t_date, 't_1' t_name, '1' t_value from dual union all select to_date('2010-02-01','YYYY-MM-DD') t_date, 't_1' t_name, '3' t_value from dual union all select to_date('2010-03-01','YYYY-MM-DD') t_date, 't_1' t_name, '4' t_value from dual union all select to_date('2010-04-01','YYYY-MM-DD') t_date, 't_1' t_name, '5' t_value from dual union all select to_date('2010-05-01','YYYY-MM-DD') t_date, 't_1' t_name, '6' t_value from dual union all select to_date('2010-06-01','YYYY-MM-DD') t_date, 't_1' t_name, '1' t_value from dual union all select to_date('2010-07-01','YYYY-MM-DD') t_date, 't_1' t_name, '1' t_value from dual ) select t_date,min_value from (select t_date,min(t_value) min_value, rank() over (order by min(t_value) ASC) RN from test1 group by t_date) where rn=1
the problem is, when I change the values in the table test1 as followst_date min_value --------- -------------------- 01-NOV-09 1 01-JAN-10 1 01-JUN-10 1 01-JUL-10 1
I get the following resultswith test1 as( select to_date('2009-11-01','YYYY-MM-DD') t_date, 't_1' t_name, '123' t_value from dual union all select to_date('2009-12-01','YYYY-MM-DD') t_date, 't_1' t_name, '2' t_value from dual union all select to_date('2010-01-01','YYYY-MM-DD') t_date, 't_1' t_name, '21' t_value from dual union all select to_date('2010-02-01','YYYY-MM-DD') t_date, 't_1' t_name, '13' t_value from dual union all select to_date('2010-03-01','YYYY-MM-DD') t_date, 't_1' t_name, '24' t_value from dual union all select to_date('2010-04-01','YYYY-MM-DD') t_date, 't_1' t_name, '15' t_value from dual union all select to_date('2010-05-01','YYYY-MM-DD') t_date, 't_1' t_name, '26' t_value from dual union all select to_date('2010-06-01','YYYY-MM-DD') t_date, 't_1' t_name, '100' t_value from dual union all select to_date('2010-07-01','YYYY-MM-DD') t_date, 't_1' t_name, '2' t_value from dual ) select t_date,min_value from (select t_date,min(t_value) min_value, rank() over (order by min(t_value) ASC) RN from test1 group by t_date) where rn=1
I expected to get the resultst_date min_value ---------- ------------- 01-JUN-10 100
any help would be appreciatedt_date min_value -------- -------------- 01-DEC-09 2 01-JUL-10 2
See you soonHello
The string "100" comes before "2" in the sort order for the same reason that 'ALL' comes before 'B '.
If you want to t_value a number, make a NUMBER, not a VARCHAR2 column.
I f you can do that, then you can try to use TO_NUMBER to convert it to a NUMBER.
but you will get an error if Island column already contains everything that cannot be interpreted as a NUMBER. -
Original title: group policy
When I try to use the system restore, I get "system restore is disabled by group policy. How can I fix this problem?
Hi bluelilly,
1. is your computer connected to a domain?
2. don't you make changes before the show?This occurs if the Configuration policy to disable is enabled on your system, either by using Group Policy or through the registry editor. For stand-alone systems Windows Vista, follow these steps:
Step 1: Using the Group Policy Editor. If your edition of Windows Vista includes the Group Policy Editor (gpedit.msc) snap-in, follow these steps:
a. Click Start, type gpedit.msc and press ENTER.
b. go to the following branch: Computer Configuration | Administrative templates | System | System restore
c. double click on disable the Configuration and set it to not configured.
Note: If the above setting is already set to not configured, set it to "Enabled" and click on apply. Return back the setting to not configured, then click on apply, OK.
d. Quit Group Policy Editor.
e. restart the computer and check the difference.Step 2: Using the registry editor
a. Click Start, type regedit.exe and press ENTER
b. navigate to the following key: HKEY_LOCAL_MACHINE-Software-policies-Microsoft-Windows NT------SystemRestore
(c) in the right pane, delete the value named DisableConfig.
d. Quit Registry Editor.
e. restart the computer and check the difference.Very important: Modifying the registry incorrectly will cause serious damage to the computer. Back up the registry until you make changes.
See Registry backupIf your computer is connected to a domain, then we recommend that you post your query toTechnet Forums Windows Vista to improve the assistance.
Visit our Microsoft answers feedback Forum and let us know what you think.
-
IOM sql Query to get the status of the failed task
Hello world
We have an obligation as we need to get the status of a particular task (say Create User in OID - Completed\Rejected status resource) for the particular user. We are able to get the status of the provisioed of resources to the user but not the status of the special mission which is trigerred for the user.can someone put some light on it. We must have the SQL query to do this.
Thanks in advance.
Kind regards
MKNHello
Use this query to get the status of the task, also check the coomentsSELECT USR. USR_LOGIN, OSI. SCH_KEY, ANN. SCH_STATUS, STA. STA_BUCKET OF
OSI, CHS, STA, MIL, TOS, PKG, OUEDRAOGO, USR, OBJ, OST
WHERE OSI.MIL_KEY = MIL.MIL_KEY
AND ANN. SCH_KEY = OSI. SCH_KEY
AND STA. STA_STATUS = SCH. SCH_STATUS
AND TOS. PKG_KEY = PKG. PKG_KEY
AND MIL. TOS_KEY = TOS. TOS_KEY
AND OUÉDRAOGO. USR_KEY = USR. USR_KEY
AND OUÉDRAOGO. OST_KEY = OST. OST_KEY
AND OST. OBJ_KEY = OBJ. OBJ_KEY
AND OSI. ORC_KEY = OUEDRAOGO. ORC_KEY
AND OBJ. OBJ_NAME = "User AD".
AND OST. OST_STATUS = "Provisioning" - filter accordinglly
AND STA. STA_BUCKET = 'pending' - filter accordinglly
AND PKG. PKG_NAME = "AD User" - filter accordinglly
AND MIL.MIL_NAME = 'System' - filter accordinglly Validation
;
Thank you
Kuldeep -
How can we use the function of group based on time
Hai sir
I had a table containing fields
EMPCODE NUMBER
EMPNAME VARCHAR2 (25)
BAR CODE VARCHAR2 (25)
VARCHAR2 (25) RESPONDENT
OUTTIME VARCHAR2 (25)
INTRTIMEIN VARCHAR2 (25)
INTROUTTIME VARCHAR2 (25)
PERTIMEIN VARCHAR2 (25);
PERTIMEOUT VARCHAR2 (25);
DATE OF ATTEND_DATE;
Who has six columns of time and I need to use the group function
For example
0815,0817,1230,1250,1645,1648,
0815 should store in timein
0817 must store in intrtimein
1250 need to store in pertimein
1230 must store in pertmeout
1645 must store in intrtimeout
1648 must store in the time-out period
If it is possible using max and min function pls tell me.
Thanks and greetings
Srikkanth.MHi, Srikanth,
It would help a Lopez, if you posted CREATE TABLE and INSERT statements for a few lines of sample data and the results desired from these data.
If you want a solution that works in your version of Oracle, say what is your version of Oracle.Are you trying to sort columns?
In other words, you are waying that people can enter data in the six columns, in any order, and you want to reorder the values so that
respondent<= intrtimein="">=><= pertimein="">=><= pertimeout="">=><= introuttime="">=><=>=>If so, you can unpivot data in 6 lines, use the ROW_NUMBER analytic function to number the lines in the order and their pivot then back in order:
MERGE INTO table_x dst USING ( WITH cntr as ( SELECT LEVEL AS n FROM dual CONNECT BY LEVEL <= 6 ) , unpivoted AS ( SELECT t.empcode , CASE c.n WHEN 1 THEN intime WHEN 2 THEN outtime WHEN 3 THEN intrtimein WHEN 4 THEN introuttime WHEN 5 THEN pertimein WHEN 6 THEN pertimeout END AS tm FROM table_x t CROSS JOIN cntr c ) , got_rnum AS ( SELECT empcode , tm , ROW_NUMBER () OVER ( PARTITION BY empcode ORDER BY tm ) AS rnum FROM unpivoted ) SELECT empcode , MAX (CASE WHEN rnum = 1 THEN tm END) AS intime , MAX (CASE WHEN rnum = 2 THEN tm END) AS intrintime , MAX (CASE WHEN rnum = 3 THEN tm END) AS perintime , MAX (CASE WHEN rnum = 4 THEN tm END) AS perouttime , MAX (CASE WHEN rnum = 5 THEN tm END) AS introuttime , MAX (CASE WHEN rnum = 6 THEN tm END) AS outtime FROM got_rnum GROUP BY empcode ) src ON (dst.empcode = src.empcode) WHEN MATCHED THEN UPDATE SET dst.intime = src.intime , dst.outtime = src.outtime , dst.intrtimein = src.intrintime , dst.introuttime = src.introuttime , dst.pertimein = src.perintime , dst.pertimeout = src.perouttime ;
It should work in Oracle 10 (and more).
The PIVOT and UNPIVOT features introduced in Oracle 11 can make it a little simpler.Perhaps it would be better to require users to enter data in the right-hand columns.
You can use CHECK constraints to ensure that intimate<= intrtimein="">=><= pertimein="">=><= pertimeout="">=><= introuttime="">=><=>=> -
Count (1) returns the null value in the Group of
Hi the gems... Good afternoon...
I read that the COUNT() function always returns 0 (zero) if there is no corresponding row in the table.
The following code returns 0 as expected:
But when I used the GROUP BY clause in the query, then he returned to nothing:SELECT COUNT(1) FROM book_table WHERE client_id = 10009 AND book_id = 5465465 AND book_sub_id = 'gfdf' AND amount = 78686
Why this is happening... Please suggest...SELECT COUNT(1) FROM book_table WHERE client_id = 10009 AND book_id = 5465465 AND book_sub_id = 'gfdf' AND amount = 78686 group by client_id,book_id,book_sub_id,amount
When you use just rely on its own (and you must use count (*) not count (1) as the optimizer based on CSSTidy will re - write internally to count (*) anyway)... then you say you want a count of all rows.
When you introduce the group by clause you say thay want returned a number of records within specific groups... but if there are no groups, he cannot give you a line for any group with its county equivalent, because there are no lines for the groups. With the grouping, you have must have at least 1 row per group to get an account for her.
-
RDP for the CSA MC using the user state
I'm trying to activate an administrator remote access to the MC via RDP. The rule is triggered, which denies this action is #262. Is there a way to allow access to the box based on user RDP State? I need what the admin group is part of a DHCP pool so I can't nail down to just its address. Documentation is not very clear in the application of States of the user.
Sorry for the long answer... I hope this helps...
YES, it is absolutely possible to do. Let's say your MC is in a group called "MC CSA Group. In this group, you have implemented policies. Beside policies are your rule failet etc... So what you need is to create a new strategy (set it to Windows or Linux, if necessary). You then create a new 'Module of rule' that you attach to the new policy that you just created. When you create the new rule Module, you'll see an article that says "steady-state". Select the option "apply this rule module if the following status conditions are met:" click the checkbox beside of "user state:". "» Selection in the State of the user list, click on 'NEW '. Here, you will need to create a user state based on what you want to be able to RDP to the CSA MC. give the new user to the user a state name. Here you have the choice, you can create a specific user (i.e. If only a domain user id must have access), or you can use a domain or Local Group. (I.e. If the Domain Admins need to access the CSA MC to the RDP). Allows that you want to use the group Active directory 'Domain Admins '... "The corresponding to groups" enter the EXACT name of the domain group (Ex: MYDOMAIN\MYGROUP). Click Save. Select the new status for the user, and then save the new rule module. Assign the new rule module to the new policy and implement the new strategy of the Group CSA MC. Finally, you need to navigate the new rule module that you created and add a NETWORK access CONTROL RULE. Create an allow rule that will allow the termsrv.exe as server TCP/3389. No matter what host (you said they were on DHCP. I recommend to create a specific DHCP scope for users, so you can lock it the most). Save the rule and generate.
-
Best way to get different counts on the same column by using a query.
Hello
I try to get three different counts of the values for a specific ID on a table. In other words, I have an Id if 1-123 and 20 records with that ID in this table, which have a value of 'Y' or 'n'. I'm looking for the number of each of these values for every 20 rows, but also a number of total values of tag values using the function count in a single query.
In this spirit, I would like to see a result set as follows.
Example of result set:
1-123 5 15 20
I thought that I would be able to do this by using the following query below, but it didn't work and I get a ' error absent expression. If anyone can provide guidance on my query below or any other way to reach my goal I would really appreciate it.
Query:
Select a.par_row_id,
countOfTagsNo.TagsNo as 'Tags not selected. "
countofTagsYes.TagsYes as 'Tags selected. "
countOfTagsTotal.TotalTags as 'Total Tags'
of siebel.s_src_xm.
(select par_row_id, count (attrib_08)
of siebel.s_src_xm
where type = 'AOI Tags' and attrib_08 = 'n')
countOfTagsNo,
(select par_row_id, count (attrib_08)
of siebel.s_src_xm
When type = "AOI Tags' and attrib_08 = 'Y')
countofTagsYes,
(select par_row_id, count (attrib_08)
of siebel.s_src_xm
When type = 'AOI Tags' and (attrib_08 = 'Y' or attrib_08 = 'n'))
countOfTagsTotal
where a.par_row_id = countOfTagsNo.par_row_id and
a.par_row_id = countofTagsYes.par_row_id and
a.par_row_id = countOfTagsTotal.par_row_id
A.par_row_id group;
Thanks in advance.
Chris
Hi Chris,
I'm not sure that's what you want but you had probably better counting with nested decode (or case):
Select a.par_row_id,
Count (case when type = 'AOI Tags' and attrib_08 = ' don't then 1 end) as "Tags not selected."
Count (case when type = 'AOI Tags' and attrib_08 = 'Y' then 1 end) as "Tags selected."
Count (case when type = 'AOI Tags' and (attrib_08 = 'Y' or attrib_08 = 'n') then 1 end) as 'Total Tags.
of siebel.s_src_xm
A.par_row_id group;
Maybe you are looking for
-
How to clone my disk to a new SSD
Hi, communities, My hardware: Apple Mac Book Pro (mid-2009), El Capitan running and an airport Time Capsule 3 TB (with Active Time Machine). I want to replace my HARD drive. It's easy to find out how to replace it in your Mac Book Pro, but it is much
-
How to reach a specific Advisor Applecare?
I had a phone to advise me today & I missed the call. He was working on a problem with my Imac & left a message on my phone that it has found the answer to my problem and would be able to confer with me tonight if it works for me. I have only his fir
-
Equium A100-147 - bought the bad battery
My Equium A100-147 is about 3 years now and won't hold its charge longer than 10 minutes so I bought a used one on eBay for a broken machine.The battery itself is quite new in terms of use-life, his laptop computer that failed! It's the wrong kind. B
-
How reduce size photos in Aperture?
How reduce size photos in Aperture?
-
USB 2.0 data transfer rate is very slow in Windows XP computer.
Original title: USB 2.0 work very slow USB 2.0 data transfer rate is very slow, what should I do?