Group function problem
Hi, I need to list the shortest string along with the number of characters in the string, so far I've come up with:
SELECT eventtitle, MIN(LENGTH(eventtitle))
FROM event
Oracle XE is giving the error "not a single-group group function", but I can't quite see how to get "eventtitle" on it's own, the function "MIN(LENGTH(eventtitle))" does give me the desired result if run by its self. I'm grateful for any assistance!
1 with t
2 as
3 (
4 select 'abcd' short_string from dual
5 union all
6 select 'a' short_string from dual
7 union all
8 select 'b' from dual
9 )
10 select short_string, rownum rn from t
11* order by length(short_string)
SQL> /
SHOR RN
a 2
b 3
abcd 1one version using analytics
1 with t
2 as
3 (
4 select 'abcd' short_string from dual
5 union all
6 select 'a' short_string from dual
7 union all
8 select 'b' from dual
9 )
10 select short_string, len from
11 (
12 select short_string, length(short_string) len, min(length(short_string)) over() min_length from t
13* ) where len = min_length
SQL>
SHOR LEN
a 1
b 1Regards
Raj
Similar Messages
-
Nested Group Function without Group By Problem
Hey everyone,
I have 3 tables as below:
TABLES
ITEM (Item_no, Item_price, desc)
DeliveryItem (delivery_no, item_no, quantity)
Delivery (delivery_no, delivery_date)
SELECT desc, MAX(SUM(quantity)) FROM DeliveryItem, Item, Delivery WHERE Item.item_no = DeliveryItem.item_no AND Delivery.delivery_no = deliveryitem.delivery_no;
And I'm trying to output description of most delivered item but I got an error like SQL Error: ORA-00978: nested group function without GROUP BY. Could you help me to fix my code?
ThanxHi,
DESC is not a good column name; you could get errors if the parser thinks it means DESCending. I used DESCRIPTION instead, below.
I think the best way is to do the SUM in a sub-query, lkike this:
WITH got_r_num AS
SELECT item_no
, SUM (quantity) AS total_quantity
, RANK () OVER (ORDER BY SUM (quantity) DESC) AS r_num
FROM deliveryitem
GROUP BY item_no
SELECT i.description
, r.total_quantity
FROM got_r_num r
JOIN item i ON r.item_no = i.item_no
WHERE r.r_num = 1
;If you want to do it without a sub-query:
SELECT MIN (i.description) KEEP (DENSE_RANK LAST ORDER BY SUM (di.quantity)
AS description
, MAX (SUM (quantity)) AS total_quantity
FROM deliveryitem di
JOIN item i ON d1.item_no = i.tiem_no
GROUP BY i.description
;If you do nested aggegate functions, then every column in the SELECT clause must be an aggregate applied to either
(a) another aggregate, or
(b) one of the GROUP BY expressions.
That's why you got the ORA-00937 error.
This second approach will only display one row of output, so If there is a tie for the item with the greatest total_quantity, only one description will be shown. The RANK method will show all items that had the highest total_quantity.
It looks like the delivery table plays no role in this problem, but it there's some reason for including it, you can join it tpo either query above.
Of course, unless you post test copies of your tables (CREATE TABLE and INSERT statements) I cn't test anything.
Edited by: Frank Kulash on Nov 6, 2010 10:57 AM -
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. -
Getting Group Function is not Allowed
Hello All....
When I run the following in the SQL command screen it works fine... But when I try to use it in APEX to populate page values, it gives me the error...
ERROR
1 error has occurred
ORA-06550: line 25, column 74: PL/SQL: ORA-00934: group function is not allowed here ORA-06550: line 24, column 1: PL/SQL: SQL Statement ignored
CODE THAT WORKS IN SQL COMMAND SCREEN
SELECT
SUM(CASE WHEN SLOT = 'Q' THEN '1' ELSE '0' END) AS C_SLOT,
SUM(CASE WHEN TEST = 'P' THEN '1' ELSE '0' END) AS C_TEST,
FROM TBL_REC;
CODE THAT GIVES ERROR ON APPLICATION EXPRESS PAGE
SELECT
SUM(CASE WHEN SLOT = 'Q' THEN '1' ELSE '0' END) INTO :P2_C_SLOT,
SUM(CASE WHEN TEST = 'P' THEN '1' ELSE '0' END) INTO :P2_C_TEST,
FROM TBL_REC;
The colums SLOT and TEST have letter codes, I just want it to count just when it matches a certain letter. In the SQL Command Screen, it is returning one row, with the counts, everything is fine. It is only a problem when I try to use it anywere on a page in Application Express.
The full version has about 20 lines that are all sum lines, but I can not even get the 2 line ver above to work.
Any thoughts?This will work .. the into clause goes after the select columns ... into var1 ,var2 etc ..
SELECT SUM(CASE
WHEN SLOT = 'Q' THEN
'1'
ELSE
'0'
END),
SUM(CASE
WHEN TEST = 'P' THEN
'1'
ELSE
'0'
END)
INTO :P2_C_SLOT, :P2_C_TEST,
FROM TBL_REC;SS -
No layer grouping functionality
Hi,
I'm not a design expert. I use Elements personally and on occassion for work related purposes. I've always found it a pleasure to work with because Elements doesn't tend to give the feeling "you can't do this, buy the pro version". It's more limited but very workable.
Now, I received a group layered file from a professional that I have to work with. And I can't do anything with it. The groups are locked. I'm stuck. I'm really really ticked off about this. I don't need to be able to apply all sorts of cool effects to a group, I just need to be able to access the layers.And Adobe has given me a big middle finger "buy the pro version buddy".
Grouping as a functionality should imho be part of Elements. Mostly to be able to easily turn aspects of design on or off easily. So, a more limited grouping functionality would be expected. Adobe could even have auto converted to linked layers or just removed the groups and allow me to access individual layers. But they didn't.They decided to block.
Utterly unacceptable and I'm glad I didn't spend the money on the new version as I intended.
Goodbye Adobe,
MarcHi,
You cannot create Groups in PSE but you can always access them in PSE. If you have a group layered file, and you want to work on it in PSE, you will find a layer saying group layer, Double click on it and you will be prompted to simplify those layers.
The only problem is you will have them merged all in one layer but will be shown your grouped layers in your layers palette.
-Swarnima -
Alternate Item Group functionality in BOM
Hi PP Gurus,
I was looking into the Alternate Item Group functionality in BOM and found it interesting for my business requirement.\
But I am facing one problem as below:
I have 3 components for Eg. A1, A2, A3 in my header material 'A'. All the three component materials are same but quailty of the 3 is different and also the standard price.
My requirement is whenever I am creating Production material for header material 'TEST_Header_Material, the system should look into A3 first (Cheapest), if not available then A2 (Cheaper) and if not then A 1(expensove of all the three).
For base quantity for A = 1EA, I have entered 1 EA for A1, A2, A3 in BOM. I have stock of A1=9, A2 = 6 and A3 = 2.
When I am creating Production Order for A = 10 EA, ,yrequirement is that the system should consider A3 first, then A2 and then A1 based upon the prority and hence should withdraw A3=2, A2=6 and A1=2 for meeting the quantity for finish product A in Production Order. But actuall the system is considering A3 but confirming it as 0, then looking into A2 again confirming it as zero and then looking into A1 and again confirming it as 0. And thus giving Missing Part list though I have sufficient quantity to cover the requirement.
That means system is only considering total quanitty.
Can you please advice?
Thank You.
Rahul.Dear Rahul,
Priority:In this field, you define the priority of the item within an alternative item group. This determines the priority for planned
withdrawal of items. Two items are assigned to an alternative item group (A1) with the following values for priority:
Item 0060 Value for priority: 02
Item 0065 Value for priority: 01
The system reads item 0065 first.
Also check these links,
concept of alternative items
Re: Alternative item in BOM
Re: NOTE 149332 : Error for material components with usage probability 0
Re: Discontinuation&Production Order
Regards
Mangalraj.S -
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 -
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 -
Has anyone had a problem with TapMedia File Manage installed on iPhone 5? I reported a WIFI functionality problem to the developer and asked for support. Instead the company has been very unprofessional by name calling me instead of logically evaluate and troubleshoot the problem
Hi AKE1919,
Welcome to the Support Communities!
The following information should help you with this:
How to report an issue with your iTunes Store, App Store, Mac App Store, or iBookstore purchase
http://support.apple.com/kb/HT1933?viewlocale=en_US
Cheers,
Judy -
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 -
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 -
Not a single-group group function very urgent
HI,
select sum(avg(wait_to))+sum(avg(idle))+sum(avg(users))+sum(avg(system)) from system_cpu
where hostid='DSCP02469' group by cpuid
this query is working
but i want cpuid group to be displayed
so i wrote query like this.
select cpuid,sum(avg(wait_to))+sum(avg(idle))+sum(avg(users))+sum(avg(system)) from system_cpu
where hOstid=' ' group by cpuid it is throwing a error
not a single-group group function.
how can get sum of avg of colums,column based on some coloum
group by column
id,sum(avg( )) i have to get
please give me solution.
send me mail to [email protected]hi,
thanku for immediate reply but
if i do that
select cpuid, a+b+c+d total_value from (select cpuid,
sum(avg(wait_to)) a, sum(avg(idle)) b,sum(avg(users)) c,sum(avg(system)) d
from system_cpu where hostid='DSCP02469' group by cpuid)
SQL> /
select cpuid, a+b+c+d total_value from (select cpuid,
ERROR at line 1:
ORA-00937: not a single-group group functionelse
select cpuid, a+b+c+d total_value from (select
sum(avg(wait_to)) a, sum(avg(idle)) b,sum(avg(users)) c,sum(avg(system)) d
from system_cpu where hostid='DSCP02469' group by cpuid)
SQL> /
select cpuid, a+b+c+d total_value from (select
ERROR at line 1:
ORA-00904: "CPUID": invalid identifier2)
can we use select in select case
can we use select sal, case when sal then select * from emp like this
with regards
shannu sarma
Maybe you are looking for
-
Importing from PhotoShop Elements to iPhoto
I moved a photo from iPhoto 8 to Adobe PhotoShop elements 6 to make some editing changes. I saved this edited copy as a JPEG item. Now iPhoto will not import this edited copy. The error dialog box states:Unreadable Files: 1. It further states: "The f
-
PowerBook G4 DVI w/Dead Internal Primary Fan, Replacement Parts Questions
Hey Everyone, I'm preparing to replace the primary fan on a PowerBook G4 DVI. I have a spare, used primary fan, but lack the rubber pins. Does anyone know where these little things can be purchased online separate from the fan kit itself? I did some
-
WiFi on my MacBook Pro works in one room but not in others
If I bring my MacBook Pro next to an iMac in one room it will connect (albeit slowly) to the internet. When I walk 2 metres into my own bedroom it simply disconnects and stops working, while my phone stays connected and at a similar speed. The MacBoo
-
Dynamic variables in Web Intelligence
Hi Team, I am new BO reports. Have already worked on Crystal reports XI. With that knowledge, I have started working in BO web Intelligence reports. I am able to create a universe and able to create a sample WebI report using the universe. SQL viewer
-
Editing photoshop web galleries
Hi I am new to web design and i have all of these galleries that photoshop has designed for me. I am using Cs2 on a pc and the gallery i used is called flash 1. I would like to move the thumbnails to the side and also put links to my blog and other t