My coding execution is slow due to Group function
Hai All
I have genetating an attendace function by day today process
My coding is
declare
bar_code varchar2(25);
in_time varchar2(25);
out_time varchar2(25);
Cursor c1 is
Select BARCODE,BARDATE,BARTIME
From temp_attendance
group by barcode,bardate,bartime
ORDER BY BARCODE,bartime;
begin
for r1 in c1 loop
declare
bar_code varchar2(25);
begin
select barcode into bar_code from dail_att where barcode=r1.barcode and attend_date=r1.bardate;
For r in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
if r1.bartime between 1630 and 1830 and r.intime between 0715 and 0915 then
-- update dail_att set outtime=(select max(bartime) from temp_attendance group by barcode,bardate
-- having temp_attendance.barcode=dail_att.barcode and temp_attendance.bardate= dail_att.attend_date );
update dail_att set outtime=r1.bartime where barcode=r1.barcode and attend_date=r1.bardate and intime is not null;
elsif r1.bartime between 1930 and 2130 and r.intime between 1145 and 1245 then
update dail_att set outtime=r1.bartime where barcode=r1.barcode and attend_date=r1.bardate and intime is not null;
--update dail_att set outtime=(select max(bartime) from temp_attendance group by barcode,bardate
-- having temp_attendance.barcode=dail_att.barcode and temp_attendance.bardate= dail_att.attend_date );
elsif r.intrin is null and r.intime is not null then
update dail_att set intrin=r1.bartime where barcode=r1.barcode and attend_date=r1.bardate and
intime is not null and introut is null and addin is null and addout is null;
elsif r.introut is null and r.intime is not null and r.intrin is not null then
update dail_att set introut=r1.bartime where barcode=r1.barcode and attend_date=r1.bardate and intime is not null and intrin is not null and addin is null and addout is null;
end if;
end loop;
exception
when no_data_found then
if r1.bartime between 0715 and 0915 or r1.bartime between 1145 and 1245 or r1.bartime between 1700 and 1800 then
insert into dail_att(barcode,intime,attend_date)
(select r1.barcode,min(r1.bartime),r1.bardate from temp_attendance group by r1.barcode,r1.bardate);
elsif r1.bartime between 0100 and 0630 then
update dail_att set outtime=r1.bartime where barcode=r1.barcode and attend_date=r1.bardate-1;
end if;
end;
end loop;
commit;
end;
when i to generate 700 records without Max function i working and takes time.But when i use MAX Function its not working and taking a lot of time why
Pls tell me some solution to rectify these problem
While using Max function with sample data it works fine..
Thanks & Regards
Srikkanth.M
Hello Sir
Thanks for your reply
As of now i have completed first part and in that little bit problems..
First step Fetch the records as text file and stores into table T1
and the next step is i have seperated the text using substring and stores in different columns of a table
There are two shifts 0815 to 1645 and 1200 and 2000
Here I rep IN and O rep OUT
Empno date time inout
001 01-01-10 0815 I
002 01-01-10 0815 I
003 01-01-10 0818 I
001 01-01-10 1100 0
001 01-01-10 1130 I
002 01-01-10 1145 0
002 01-01-10 1215 I
004 01-01-10 1200 I
005 01-01-10 1215 I
004 01-01-10 1315 O
004 01-01-10 1345 I
001 01-01-10 1645 0
002 01-01-10 1715 0
003 01-01-10 1718 0
004 01-01-10 2010 0
005 01-01-10 2015 0
This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
T2 contains like this
Empno Intime Intrin Introut Outtime Date
001 0815 1100 1130 1645 01-01-10
002 0815 1145 1215 1715 01-01-10
003 0818 1718 01-01-10
004 1200 1315 1345 2010 01-01-10
005 1215 2015 01-01-10
This what i am trying to do man but i have little bit problems Pls give some solution with good example
Thanks & Regards
Srikkanth.M
Similar Messages
-
Sql query slowness due to rank and columns with null values:
Sql query slowness due to rank and columns with null values:
I have the following table in database with around 10 millions records:
Declaration:
create table PropertyOwners (
[Key] int not null primary key,
PropertyKey int not null,
BoughtDate DateTime,
OwnerKey int null,
GroupKey int null
go
[Key] is primary key and combination of PropertyKey, BoughtDate, OwnerKey and GroupKey is unique.
With the following index:
CREATE NONCLUSTERED INDEX [IX_PropertyOwners] ON [dbo].[PropertyOwners]
[PropertyKey] ASC,
[BoughtDate] DESC,
[OwnerKey] DESC,
[GroupKey] DESC
go
Description of the case:
For single BoughtDate one property can belong to multiple owners or single group, for single record there can either be OwnerKey or GroupKey but not both so one of them will be null for each record. I am trying to retrieve the data from the table using
following query for the OwnerKey. If there are same property rows for owners and group at the same time than the rows having OwnerKey with be preferred, that is why I am using "OwnerKey desc" in Rank function.
declare @ownerKey int = 40000
select PropertyKey, BoughtDate, OwnerKey, GroupKey
from (
select PropertyKey, BoughtDate, OwnerKey, GroupKey,
RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
from PropertyOwners
) as result
where result.[Rank]=1 and result.[OwnerKey]=@ownerKey
It is taking 2-3 seconds to get the records which is too slow, similar time it is taking as I try to get the records using the GroupKey. But when I tried to get the records for the PropertyKey with the same query, it is executing in 10 milliseconds.
May be the slowness is due to as OwnerKey/GroupKey in the table can be null and sql server in unable to index it. I have also tried to use the Indexed view to pre ranked them but I can't use it in my query as Rank function is not supported in indexed
view.
Please note this table is updated once a day and using Sql Server 2008 R2. Any help will be greatly appreciated.create table #result (PropertyKey int not null, BoughtDate datetime, OwnerKey int null, GroupKey int null, [Rank] int not null)Create index idx ON #result(OwnerKey ,rnk)
insert into #result(PropertyKey, BoughtDate, OwnerKey, GroupKey, [Rank])
select PropertyKey, BoughtDate, OwnerKey, GroupKey,
RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
from PropertyOwners
go
declare @ownerKey int = 1
select PropertyKey, BoughtDate, OwnerKey, GroupKey
from #result as result
where result.[Rank]=1
and result.[OwnerKey]=@ownerKey
go
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
I had to buy a new iPhone, how do I retrieve my stuff that was backed up in my iCloud account? The guy at the apple store said it could take a few days iCloud was running real slow due to so many new accounts, is that true?
No problems backing up iCloud here.
Tap Settings > iCloud > Storage & Backup
Switch iCloud Backup On -
Error while using group function
Oracle forms6i
Hai
While i am compile my coding it compile successfully, but when i tried to executes i shows error in group function
my coding is
if (cnt<>0 ) then
select BARCODE,INTIME,OUTTIME into today_bar,today_in,today_out from dail_att where BARCODE= :Barcode
and ATTEND_DATE = :bardate;
update dail_att set outtime = max(:bartime) where barcode= :barcode
and ATTEND_DATE = :bardate;
else
if (cnt2<>0 ) then
select INTIME,OUTTIME into yest_in,yest_out from dail_att where BARCODE= :Barcode
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= :barcode
and ATTEND_DATE = :bardate-1;
else
insert into dail_att(barcode,intime,attend_date)
values(:barcode,min(:bartime),:bardate);
end if;
else
if :bartime between 0100 and 0630 then
insert into dail_att(barcode,intime,attend_date)
values(:barcode,min(:bartime),:bardate-1);
update dail_att set outtime = max(:bartime) where barcode= :barcode
and ATTEND_DATE = :bardate-1;
else
insert into dail_att(barcode,intime,attend_date)
values(:barcode,:min(bartime),:bardate);
end if;
end if;
end if;
while i am trying to this groupfunction it throws error while i use having tell me how to use group function and where
to use
Regadrs
Srikkanth.MHai sir
I had a table that contain fields
EMPCODE NUMBER
EMPNAME VARCHAR2(25)
BARCODE VARCHAR2(25)
INTIME VARCHAR2(25)
OUTTIME VARCHAR2(25)
INTRTIMEIN VARCHAR2(25)
INTROUTTIME VARCHAR2(25)
PERTIMEIN VARCHAR2(25);
PERTIMEOUT VARCHAR2(25);
ATTEND_DATE DATE ;
Consider that a table with 6 fields ie timein,intrtimein,pertimein,pertimeout,intrtimeout,timeout
I have generating a attendance table and a table contain 6 various times for an employees and we need to arrange it in order
0815,0816,1230,1250,1645,1646
If 0815 is the starting time then timein ie mintime
0816 stored to be in intrtime
then1250 then it stored in pertimein
then 1230 then it stored in pertimeout
then 1645 stored in intrtimeout
then 1646 stored in timeout
I tried with max and min function but its not working properly pls tell me some solutions
Thanks & Regards
Srikkanth.M -
ORA-00935: group function is nested too deeply - SQL Query is correct...
select s.sname, to_char(sum(t.amount), 'fm$999999.00')
from transactions t, salespeople s
where t.sid = s.sid
group by s.sname, t.year
having (t.year = 1997) and max(sum(t.amount));
I'm trying to print sales person name who had the highest total sell in 1997. I do not see where did i go wrong in the above query...Isn't nested group function allowed?!
What about this?
select s.sname, to_char(sum(t.amount), 'fm$999999.00') as "TOTAL"
from transactions t, salespeople s
where t.sid = s.sid
group by s.sname, t.year
having (t.year = 1997) and sum(t.amount) = (select max(amount) from transactions where year = 1997);
It should return something, but it does not due lack of data in database. I think the above code is correct. I just need to confirm from you...select s.sname, (case when sum(t.amount) > sum(t2.amount)
then sum(t.amount)
else sum(t2.amount)
end) "TOTAL"
from transactions t, salespeople s
where t.sid = s.sid
group by s.sname, t.year
having t.year = 1997
union
select s.sname, sum(t2.amount)
from transactions t2, salespeople s
where t2.sid = s.sid
group by s.sname, t2.year
having t2.year = 1997;
Your code looks good, but it does not work in Oracle Developer...
The above should work isn't it? The inner query gets executed then the outer one so the result i get in -
Getting an error - group function not allowed here
Below is the merge statement...
getting an error - group function not allowed here
WHY????
merge into summary
using
(select
a.user_id,
min(a.start_time_utc),
max(a.end_time_utc),
sum(a.duration_seconds),
/*total_upload
total_download
total_traffic,*/
max(r.package_id),
last_usage_charge, -------hard coded
max(r.peak_rate),
max(r.bst_plantype),
max(r.free_value), ---for free value
a.IsPeak,
sum(a.TotalDiscount)
from aaa_sessions a,rate_plan r,subscriber_info si
where
si.EXTERNAL_ID=a.USER_ID
and
si.PACKAGE_ID=r.PACKAGE_ID
group by
user_id,bst_plantype,ispeak)t ------do we need to use alias here
on
(summary.user_id=t.user_id
and
summary.type_of_summary=t.bst_plantype
and
summary.ispeak=t.ispeak)
When matched then
update
set
start_date =decode((t.start_time_utc-summary.start_date)-abs(t.start_time_utc-summary.start_date),0,summary.start_date,t.start_time_utc),
end_date=decode((t.end_time_utc-summary.end_date)-abs(t.end_time_utc-summary.end_date),0,t.end_time_utc,s.end_date),
total_duration=summary.total_duration+sum(duration_seconds),
total_upload=summary.total_upload+sum(upload_bytes),
total_download=summary.total_download+sum(download_bytes),
total_traffic=summary.total_upload+sum(upload_bytes)+summary.total_download+sum(download_bytes)
When not matched then
INSERT
(user_id ,
start_date,
end_date,
total_duration,
/*total_upload
total_download
total_traffic,*/
rate_plan_id,
last_usage_charge,
peak_rate,
type_of_summary,
IsPeak,
TotalDiscount)
VALUES
(t.user_id,
t.start_time_utc,
t.end_time_utc,
t.duration_seconds,
/*t.output_bytes,
t.input_bytes,
t.output_bytes+aa.input_bytes,*/
t.PACKAGE_ID,
1, ---hard coded the value
t.PEAK_RATE,
t.BST_PLANTYPE,
t.ispeak,
t.free_value);This is the query,...
Its giving no complilation errors..
I have not used aggregate functions in the insert/update..
have used only decode...
and nowhere i found that aggegate functions not allowed in the insert/update stmts of merge..
Can u please post a link where it is mentioned...
MERGE INTO summary
USING (SELECT a.user_id, MIN (a.start_time_utc) stc,
MAX (a.end_time_utc) etc, SUM (a.duration_seconds) ds,
SUM (a.download_bytes) download,
SUM (a.upload_bytes) upload, MAX (r.package_id) pkg_id,
MAX (r.peak_rate) p_rate, MAX (r.offpeak_rate)
ofp_rate,
MAX (r.bst_plantype) plan_type,
SUM (r.free_value) free_val, a.ispeak,
MAX (r.peak_pulse) p_pulse,
MAX (r.offpeak_pulse) ofp_pulse
FROM aaa_sessions a, rate_plan r, subscriber_info si
WHERE si.external_id = a.user_id
AND si.package_id = r.package_id
GROUP BY user_id, bst_plantype, ispeak) t
ON ( summary.user_id = t.user_id
AND summary.type_of_summary = t.plan_type
AND summary.rate_plan_id = t.pkg_id
AND summary.ispeak = t.ispeak)
WHEN MATCHED THEN
UPDATE
SET start_date =
DECODE ( (t.stc - summary.start_date)
- ABS (t.stc - summary.start_date),
0, summary.start_date,
t.stc
end_date =
DECODE ( (t.etc - summary.end_date)
- ABS (t.etc - summary.end_date),
0, t.etc,
summary.end_date
total_duration = summary.total_duration + t.ds,
total_download = summary.total_download + t.download,
total_upload = summary.total_upload + t.upload,
total_traffic =
summary.total_upload
+ t.upload
+ summary.total_download
+ t.download,
last_usage_charge =
DECODE (t.plan_type,
0, (t.ds - t.free_val)
/ DECODE (t.ispeak, 0, t.ofp_pulse, p_pulse)
* DECODE (t.ispeak, 0, t.ofp_rate, t.p_rate),
((t.download + t.upload) - t.free_val
* DECODE (t.ispeak, 0, t.ofp_rate, t.p_rate)
WHEN NOT MATCHED THEN
INSERT (user_id, start_date, end_date, total_duration,
total_download, total_upload, total_traffic, rate_plan_id,
last_usage_charge, peak_rate, type_of_summary, ispeak,
totaldiscount)
VALUES (t.user_id, t.stc, t.etc, t.ds, t.download, t.upload,
t.download + t.upload, t.pkg_id,
DECODE (t.plan_type,
0, (t.ds - t.free_val)
/ DECODE (t.ispeak, 0, t.ofp_pulse, p_pulse)
* DECODE (t.ispeak, 0, t.ofp_rate, t.p_rate),
((t.download + t.upload) - t.free_val
* DECODE (t.ispeak, 0, t.ofp_rate, t.p_rate)
t.p_rate, t.plan_type, t.ispeak, t.free_val);
COMMIT; -
Function group / Function modules approvals
Hi,
We have couple of function modules related to RFC / BAPI in QA we need to give approvals before we move them to production.
What precautions do we need to take before approving?
How to segregate Function groups / Function modules?
Thanks,
RamWell you should test function groups and function module coding as per your normal procedures. They are widely used.
Whether they are accessible depends on your roles, right?
Which release are you on?
Prior release 7.01 you can only control at function group level with object S_RFC.
Subsequently you can use RFC_TYPE 'FUNC' to control at module name level if FUGR fails.
Luckily, this check is central and to my knowledge only one developer ever hardcoded it for list outputs, so you should be okay to convert for manual authorizations.
For standard ones from the menu, you will need to deactivate S_RFC (there is not option to un-merge, unfortunately..........). Easiest is to get the names from the menu and paste them into the manual authorization, or use a Su24 "dummy" for the role or scenario.
Dummy's are usefull workarounds and protect you against upgrades as well... (when SAP adds a load of stuff because GRC needs it, and then toasts your roles, sets active auths to inactive and adds new ones which are merged automatically...)
Cheers,
Julius -
Issue with not a single-group group function error
Hello PL/SQL Gurus,
I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version and
Once I am using the following query –
SELECT s.sym,
t.tag_trade_method trade_method,
astd.tag_trade_sector,
iss.gics_sector_dsc sector,
d.date_dt trade_date,
c.wmc_curcy_cd_alpha curcycode,
amd.brkr_nm,
SUM(atdf.notional_amt) trd_notional,
SUM(atdf.trd_qty) trd_qty,
ard.buy_sell_ind,
td.person_init
FROM alloc_tran_det_fact atdf,
date_dim d,
alloc_trade_tag_dim t,
security_dim s,
currency_dim c,
person_dim td,
access_method_dim amd,
alloc_sec_tag_dim astd,
alloc_ref_dim ard,
issuer_dim iss
where atdf.alloc_trd_tag_dim_key = t.alloc_trade_tag_dim_key AND
atdf.alloc_sec_tag_dim_key = astd.alloc_sec_tag_dim_key AND
ard.alloc_ref_dim_key = atdf.alloc_ref_dim_key AND
atdf.isr_dim_key = iss.isr_dim_key AND
atdf.trd_dt_key = d.date_dim_key AND
atdf.sec_dim_key = s.sec_dim_key AND
t.tag_valid_trade_flg = 'Y' AND
atdf.locl_curcy_flg = 'Y' AND
d.date_dim_key BETWEEN 20120405 AND 20120405 AND
c.curcy_dim_key = atdf.curcy_dim_key AND
td.person_dim_key = atdf.trdr_dim_key AND
atdf.exec_brkr_dim_key = amd.access_method_dim_key AND
amd.level_cd = 'B'
and t.tag_trade_method in('ALGO','CAPITAL','DMA','NATURAL','WORKING')
then it throw the error –
ORA-00937: not a single-group group function
If I am using something like –
SELECT s.sym,
t.tag_trade_method trade_method,
astd.tag_trade_sector,
iss.gics_sector_dsc sector,
d.date_dt trade_date,
c.wmc_curcy_cd_alpha curcycode,
amd.brkr_nm,
SUM(atdf.notional_amt) trd_notional,
SUM(atdf.trd_qty) trd_qty,
td.person_init
FROM alloc_tran_det_fact atdf,
date_dim d,
alloc_trade_tag_dim t,
security_dim s,
currency_dim c,
person_dim td,
access_method_dim amd,
alloc_sec_tag_dim astd,
issuer_dim iss
WHERE atdf.alloc_trd_tag_dim_key = t.alloc_trade_tag_dim_key AND
atdf.alloc_sec_tag_dim_key = astd.alloc_sec_tag_dim_key AND
atdf.isr_dim_key = iss.isr_dim_key AND
atdf.trd_dt_key = d.date_dim_key AND
atdf.sec_dim_key = s.sec_dim_key AND
t.tag_valid_trade_flg = 'Y' AND
atdf.locl_curcy_flg = 'Y' AND
d.date_dim_key BETWEEN 20120102 AND 20120401 AND
c.curcy_dim_key = atdf.curcy_dim_key AND
td.person_dim_key = atdf.trdr_dim_key AND
atdf.exec_brkr_dim_key = amd.access_method_dim_key AND
amd.level_cd = 'B'
and t.tag_trade_method in('ALGO','CAPITAL','DMA','NATURAL','WORKING')
GROUP BY t.tag_trade_method,
d.date_dt,
c.wmc_curcy_cd_alpha,
td.person_init,
amd.brkr_nm,
astd.tag_trade_sector,
iss.gics_sector_dsc
then it works fine. I know that due to aggeregate functions we need to use Group By, but why to put Group By on different non aggregate columns,
As my intension is to fetch the records for defined date range Group By Symbol (s.sym), Kindly help me with this.
Thanks to all of you in advance for providing you valuable time and efforts.
Edited by: user555994 on May 11, 2012 2:20 AMYou do need to group by these columns
t.tag_trade_method,
d.date_dt,
c.wmc_curcy_cd_alpha,
td.person_init,
amd.brkr_nm,
astd.tag_trade_sector,
iss.gics_sector_dsc
as they don't have aggregate functions applied to them. -
How to use group function in insert or update
Hai All
How can we use group function in insert or update statement
I am generating an attendance so i have different set of timing for example
0800,1200,1230, 1700 and i need to insert into these data into table with min value to intime and max value to
outtime and othere to inertval time in or out
Pls tell me with some example
For example
For INSERT
insert into T2 (barcode,empcode,intime,attend_date)
values(r2.cardn,r2.enpno,MIN(r2.ptime),r2.pdate);
For UPDATE
update dail_att set outtime= MAX(r2.ptime) where empcode=r2.enpno and barcode=r2.cardn and
attend_date=r2.pdate;
Here instead of where i need to use having so pls tell how to use
Thanks & Regards
Srikkanth.MHai Man
R2 is not a table name its a record
Let me explain clearly
I have to generate daily attendance for lot of employees So i have two table t1 and t2
T1 consist of three column empno,date,time
T2 consist of empno,name,date,intime,outtime,intrin,introut
So now i need to give the T1 Min value Of time to T2 Intime and T1 Max value of Time to T2 Outtime fields so there so many records while i am using
max(time) it gives the max value of all so i seperated by group function so now i have an error in subquery ie it is an single row subquery so i need to use multiple row subquery how i can use multiple row subquery in update statement
Thanks In Advance
Srikkanth.M -
PL/SQL equivalent of T-SQL - "group function is not allowed here"
Hi all, hope someone can give me a hand as I'm pretty stuck! I have been trying to convert some MS SQL Server T-SQL statements into Oracle PL/SQL and am stuck on the below one:
SELECT
CA.AssessmentID,
(SELECT ProductName + ISNULL(' - ' + PrincipalBenefit,'')
FROM rptPolicySnapshot WHERE PolicyID = MAX(CA.PolicyID)
AND SnapshotID = 1),
MAX(CA.PolicyID)
FROM rptClaimInvoiceLineSnapshot CIL
INNER JOIN rptClaimAssessmentSnapshot CA
ON CIL.AssessmentID = CA.AssessmentID
AND CIL.SnapshotID = CA.SnapshotID
WHERE CIL.SnapshotID = 1
GROUP BY CA.AssessmentID
This works fine in MSSQL but returns the below error in Oracle:
'ORA-00934: group function is not allowed here'
If I take out the subquery the query works fine.
Any ideas as to the syntax? I am new to Oracle so not sure as to how I should go about writing this.
Thanks in advance!
LeoWITH x AS (SELECT ca.assessmentid,
MAX (ca.policyid) policy_id
FROM rptclaiminvoicelinesnapshot cil
INNER JOIN rptclaimassessmentsnapshot ca
ON cil.assessmentid = ca.assessmentid
AND cil.snapshotid = ca.snapshotid
WHERE cil.snapshotid = 1
GROUP BY ca.assessmentid
SELECT x.assessment_id,
x.policy_id,
productname + decode(principalbenefit,null,null,' - ' || principalbenefit ) prodname
FROM rptpolicysnapshot, x
WHERE policyid = x.policy_id
AND snapshotid = 1I think that's in the neighbourhood. -
Is there a way to create a group function?
I want to create a group function like max,sum,count for a
pl/sgl function. This group function will be something like max
(let's call it max2) but it will return the second highest value
of a group.
Any ideas anyone?Since you might not completely understand what i mean i give you
this example:
the ranktest table is:
A B C
a b 1
a b 1
a b 5
a b 12
a b 7
b c 1
b c 3
b c 2
b c 4
b c 8
c d 4
c d 3
c d 6
c d 1
c d 2
c d 12
c d 7
c d 3
a b 5
c d 12
SELECT A,B,C
FROM (
SELECT A,B,C, dense_rank() over (
PARTITION BY A,B
ORDER BY C desc) AS sorted_c
FROM ranktest a)
WHERE sorted_c = 2
-- this way we get the c column to have the 2nd highest value
-- for each set of A and B
--RESULT
a b 7
b c 4
c d 7
SELECT a.A,a.B, sum(a.C), count(a.C)
FROM ranktest a
GROUP BY a.A,a.B
-- this way we get the group functions to work on two of the
-- columns
--RESULT
a b 31 6
b c 18 5
c d 50 9
The result that i want is
a b 31 6 7
b c 18 5 4
c d 50 9 7
My question is can this be done in a single select statement. I
know it can be done with an intermediate step (of the creation
of a temp table).
Plus i would like to ask the experts, would a single select
statement be more efficient?
NOTE: the tables and data are just test data. The real tables
and data and the select query are different. The real ranktable
has about 1 million records. That's why i am worried about
efficiency. -
How to create a user_defined grouping function?
I need to create a user_defined function and use it in my sql statement.
I know the user_defined function can be used anywhere the build-in function can be used.In oracle,there are grouping functions.
How can I create a user_defined grouping function and I can use it in my sql statement.Hi, can you explain exactly what you are trying to achieve:
SQL> create or replace function my_func return number as
2 begin
3 return 5;
4 end;
5 /
Function created.
SQL> select deptno,my_func(),max(sal)
2 from emp
3 group by deptno,my_func()
4 /
DEPTNO MY_FUNC() MAX(SAL)
10 5 5000
20 5 3000
30 5 2850 -
ORA-00978 without group function
I've experienced a strange problem with oracle 11g.
I've retrieved the oracle exception ORA-00978 even if there was no group function in my query.
I supposed was a problem in the optimizer so I rebuild the tables statistics, after that the query was execute successfully.
Does anyone has an idea what the problem is?
Is possible that a bug exists in the 11g optimizer?
My oracle version is:
Oracle Database 11g Enterprise Edition 11.1.0.6.0 64bit Production
the query i tried is:
SELECT *
FROM TBCALENDAR Cal,
VWCALENDARACTIVITY CA,
VWSE R,
TBSCHEDULERPARTITION P,
TBREGION REG,
TBRESOURCE RES ,
TBZIPCITY z
WHERE Res.id=Cal.RESOURCE_ID
AND R.RESOURCE_ID=RES.ID
AND Cal.ACTIVITY_ID=CA.ID
AND CA.SCHEDULING=1
AND Cal.SCHEDPARTITION_ID IN
(select item.PARTITION_ID
from tbidcprofile prof,
tbidcpartitem part,
tbschedpartitem item
where prof.USERPROFILE_ID=4
and prof.IDCPARTITION_ID=part.PARTITION_ID
and part.BUSINESSUNIT_ID=item.BUSINESSUNIT_ID
and part.REGION_ID=item.REGION_ID )
AND TRUNC(Cal.START_DT)=trunc(sysdate)
AND P.ID=Cal.SCHEDPARTITION_ID
AND REG.ID(+)=Cal.WORKREGION_ID
AND Z.GEOLOCATION_ID(+)=Cal.HOMEGEOLOC_ID;
VWCALENDARACTIVITY and VWSE are two views, but I can select from them without any problem.
I've also tried to remove one view at a time an the error occurs only when the query uses both view at the same time.
Thanks
Renzouser479513 wrote:
VWCALENDARACTIVITY and VWSE are two views, but I can select from them without any problem.
I've also tried to remove one view at a time an the error occurs only when the query uses both view at the same time.
What are the views definition ?
Nicolas. -
How to create a grouping function
How to create a grouping function ?? For example, can I create a function:myavg and I can use it like :
select col_a, col_b, myavg(col_c)
from table_a
group by col_a, col_b
Thanks in advance !!
nullI don't think that you can create a grouping function in Oracle, but you can create a function and use it in Select statments.
null -
Hello all,
How can I use a nested group function in a select statement?
For example: select sum(count(id), column a, column b from table_name group by???
Thanks in advance!select sum(CNT) column_a, column_b
from (select count(id), column_a, column_b from table_name
group by column_a, column_b)
group by column_a, column_b
Maybe you are looking for
-
Completely unacceptable service and billing for a major utility/service provider. I have not been able to send or receive calls for three days and can't get an explanation or estimated time of recover. There's not a business contingency plan? The o
-
Problem displaying a report from within Oracle 10g forms. After a lot of work, we are able to access and actually display a report directly from Internet explorer and view the report from the report server as well. The successful url was: http://york
-
hi guys earlier today i installed a wondershare youtube download program called allmytube. it even comes w/ an uninstaller .. fooled around with it for a while but came to the conclusion that i wasn't about to buy it WITHOUT being able to fully
-
Itunes doesnt open when iphone 5 is connected to pc
itunes doesnt recognize iphone 5 when connected to pc
-
Clickbox Shortcut Alt + Not Working
I have an application that I am doing some training simulations for. The shortcuts in this app are all based on the Alt key + another. When I enter an Alt+ shortcut on a clickbox object, it doesn't work in Cp5. It had been a while since I had done it