Group function in coldfusion
Hello does anyone know how to use the group function in
coldfusion
my tables that out-puts to a html
is outputing multiple CEENO
for example CEENO
11111
11111
11111
11111
someone here said to use the group function in coldfusion
do you know where i can put it?
<table border="2" cellpadding="2" cellspacing="0">
<tr>
<th>Record Number</th>
<TH>PEA_id</TH>
<th width="120">CEENO</th>
<TH>Address</TH>
<TH>ZipCode</TH>
<th>AdvisoryDate</th>
</tr>
<cfloop query="getthecases">
<tr bgcolor="<cfif currentrow mod
2>GHOSTWHITE<cfelse>WHITE</cfif>">
<td>#CurrentRow#</td>
<td>#PEA_id</td>
<Td>#CEENO#</td>
<td>#ST_NO# #ST_initial# #st_dir#</td>
<td>#ZipCode#</td>
<td>#dateformat(ADVISORY_DATE,"mm/dd/yyyy")#</td>
</tr>
</cfloop>
</table>
What they are referencing is the group attribute of the
CFOUTPUT tag:
<cfoutput query="qryName" group="groupName">
#dbgroupvar#
<cfoutput>
#otherdbdata#
</cfoutput>
</cfoutput>
However, you have to write the correct SQL to get this to
work and that includes using the ORDER BY clause in your SQL
Statement to specify what column on which to group the output.
For example, the following query would get all employees from
the database and order them by the department for which they work:
<cfquery name="qTest" datasource="dsn">
SELECT name, title, department
FROM employee
ORDER BY department
</cfquery>
We can use the group attribute of cfoutput to show all
employees for each department:
<cfoutput query="qTest" group="department">
<h1>#department#</h1>
<table>
<cfoutput>
<tr>
<td>#name#</td>
<td>#title#</td>
</tr>
</cfoutput>
</table>
Hope this helps.
Cheers,
Craig
Similar Messages
-
Goup by in oracle vs group function in coldfusion
Hello
what is the difference between goup by in oracle vs group
function in coldfusion?It's easier to list the similarities:
Both use the word "group".
Other than that: they're different things.
Both are well documented in their respective documentation
sources (which
are avaialble online). Suggest you read up.
Adam -
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 -
Does anybody can suggest me how do i write SQL FUNCTIONS in
Coldfusion, i tried to run a SQL FUNCTION in a <cfquery> but
that returned me an Coldfusion Error. do i need to use
<cfstoredProc> for that or. any other <tag available>
<cfquery name="blahblah" datasource="#dsn#">
CREATE FUNCTION [dbo].[ConcatUserGroups](@UserID int)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @groupname Varchar(2000)
SET @groupname = ''
SELECT @groupname = @groupname + ', ' + CONVERT(varchar(20),
u.group_name)
FROM [user] A
JOIN UserGroup_combo UG
ON UG.ug_userID = a.[USER_ID]
JOIN usergroup U
ON UG.ug_groupID = u.group_ID
WHERE A.[USER_ID] = @userID
AND LEN(ISNULL(U.group_name,'')) > 0
ORDER BY U.GROUP_NAME
IF(LEN(@groupname) >= 2) BEGIN
SET @groupname = RIGHT(@groupname,(LEN(@groupname) - 2))
END
RETURN @groupname
END
GO
</cfquery>There's no such thing as "coldfusion sql" (sic). Everything
between the
<cfquery> tags is simply resolved (ie: CF runtime
statements between
pound-signs) and passed straight to the DB drivers, and
thence to the DB
itself. CF does no SQL processing at all.
Your error kind of suggests a syntac error AFTER the query
has been
executed though.
Could you post some code, and point out which precise line is
erroring?
Adam -
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. -
can we call a php function into coldfusion??
if anybody knows that let me know....Nope, as IIS can only pass one page to one handler, so it gets passed to ColdFusion *or* PHP. The only way it would work is to have a page with an iFrame containing a PHP page, but that's not calling a PHP function from ColdFusion.
Dare I ask what it is you're trying to achieve exactly? If it's an extremely complicated function that can't possibly be rewritten, you'd probably want to wrap it up in a webservice and call it from CF. -
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 -
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 -
Nested group function without group xmlagg
I am getting nested group function without group by xmlagg when using the xmlagg function inside another xmlagg function. Find the table structure and sample data here,
CREATE TABLE "TEST_TABLE"
("KEY" NUMBER(20,0),
"NAME" VARCHAR2(50 ),
"DESCRIPTION" VARCHAR2(100 )
Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (1,'sam','desc1');
Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (2,'max','desc2');
Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (3,'peter',null);
Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (4,'andrew',null);
select
XMLSerialize(document
xmlelement("root",
xmlagg(
xmlelement("emp"
, xmlforest(Key as "ID")
, xmlforest(name as "ename")
, xmlelement("Descriptions",
xmlagg(
xmlforest(description as "Desc")
) as clob indent
) as t
from test_table;Then i removed the xmlagg function from the above select query and used xmlelement instead
select
XMLSerialize(document
xmlelement("root",
xmlagg(
xmlelement("emp"
, xmlforest(Key as "ID")
, xmlforest(name as "ename")
, xmlelement("Descriptions",
xmlforest(description as "Desc")
) as clob indent
) as t
from test_table;This is working fine, but xml created with empty elements for Descriptions element for key 3 and 4 which has null values. I need don't need Descriptions element in the xml when it has null value. Please help me to resolve this.You can do it with a correlated subquery :
SQL> select xmlserialize(document
2 xmlelement("root",
3 xmlagg(
4 xmlelement("emp"
5 , xmlforest(
6 t.key as "ID"
7 , t.name as "ename"
8 , (
9 select xmlagg(
10 xmlelement("Desc", d.description)
11 order by d.description -- if necessary
12 )
13 from test_desc d
14 where d.key = t.key
15 ) as "Descriptions"
16 )
17 )
18 )
19 ) as clob indent
20 )
21 from test_table t;
XMLSERIALIZE(DOCUMENTXMLELEMEN
<root>
<emp>
<ID>1</ID>
<ename>sam</ename>
<Descriptions>
<Desc>desc1_1</Desc>
<Desc>desc1_2</Desc>
<Desc>desc1_3</Desc>
</Descriptions>
</emp>
<emp>
<ID>2</ID>
<ename>max</ename>
<Descriptions>
<Desc>desc2_1</Desc>
<Desc>desc2_2</Desc>
<Desc>desc2_3</Desc>
</Descriptions>
</emp>
<emp>
<ID>3</ID>
<ename>peter</ename>
</emp>
<emp>
<ID>4</ID>
<ename>andrew</ename>
</emp>
</root>
Or an OUTER JOIN + GROUP-BY :
select xmlserialize(document
xmlelement("root",
xmlagg(
xmlelement("emp"
, xmlforest(
t.key as "ID"
, t.name as "ename"
, xmlagg(
xmlforest(d.description as "Desc")
order by d.description -- if necessary
) as "Descriptions"
) as clob indent
from test_table t
left outer join test_desc d on d.key = t.key
group by t.key
, t.name
;Edited by: odie_63 on 11 juil. 2012 14:54 - added 2nd option -
Grouping Function usage in SQL
All,
How does grouping function work, does it also depends on the sequence of columns used in group by rollup
select deptno,job, group_id(), sum(sal), grouping(deptno) , grouping(job)
from emp
group by rollup (deptno, job)
If the query is run by "rollup(job,deptno)" grouping (deptno) returns 1 where as if "rollup(deptno,job)" grouping (deptno) returns 0.
Does the column sequence in group by rollup decides the returning of grouping(deptno) function. I feel to have some misunderstanding of the way its said in ORACLE documentation. We referred to the below link for our understanding.
http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions071.htm
Request the PRO's to discuss and clarify on this.Hi,
ramarun wrote:
All,
How does grouping function work, GROUPING (x) returns 1 if the current row represents a superaggregate of x, and 0 otherwise. In other words, if GROUPING (x) is 0, then the row represents a single value of x. If GROUPING (x) is 1, then the row represents a total of all values of x.
For example the query you posted may produce results like this:
` DEPTNO JOB GROUP_ID() SUM(SAL) GROUPING(DEPTNO) GROUPING(JOB)
20 ANALYST 0 6000 0 0
ANALYST 0 6000 1 0
10 CLERK 0 1300 0 0
20 CLERK 0 1900 0 0
30 CLERK 0 950 0 0
CLERK 0 4150 1 0
10 MANAGER 0 2450 0 0
20 MANAGER 0 2975 0 0
30 MANAGER 0 2850 0 0
MANAGER 0 8275 1 0
10 PRESIDENT 0 5000 0 0
PRESIDENT 0 5000 1 0
30 SALESMAN 0 5600 0 0
SALESMAN 0 5600 1 0
0 29025 1 1Look at the last three rows. On this row
` DEPTNO JOB GROUP_ID() SUM(SAL) GROUPING(DEPTNO) GROUPING(JOB)
30 SALESMAN 0 5600 0 0GROUPING (deptno) is 0; so the row represents only deptno=30.
GROUPINT (job) is 0, so the row represents only job='SALESMAN'.
SUM (sal) is 5600, so the total salary of all salesmen in department 30 is 5600.
Now look at this row:
` DEPTNO JOB GROUP_ID() SUM(SAL) GROUPING(DEPTNO) GROUPING(JOB)
SALESMAN 0 5600 1 0GROUPING (deptno) is 1; so the row does not represent any one deptno; it is a superaggregate of all deptnos. Notice that the deptno column is NULL, even though there are no rows in the table where deptno is NULL.
GROUPING (job) is 0, so the row represents only job='SALESMAN'.
SUM (sal) is 5600, so the total salary of all salesmen in any department is 5600. (As it happens, all the salesmen are in department 30, so this sum is the same as on the previous row.)
Now look at the last row:
` DEPTNO JOB GROUP_ID() SUM(SAL) GROUPING(DEPTNO) GROUPING(JOB)
0 29025 1 1GROUPING (deptno) is 1; so the row does not represent any one deptno; it is a superaggregate of all deptnos. Notic that both deptno and job are both NULL on this row of output, even though neither column is ever NULL in the table.
GROUPING (job) is 0, so the row represents only job='SALESMAN'.
SUM (sal) is 5600, so the total salary of people with any job and any department is 29025.
does it also depends on the sequence of columns used in group by rollup Excellent question! Try it an see. Change the order or columns in the GROUP BY clause and see. If you get different results, then the order does matter.
select deptno,job, group_id(), sum(sal), grouping(deptno) , grouping(job)
from emp
group by rollup (deptno, job) If the query is run by "rollup(job,deptno)" grouping (deptno) returns 1 where as if "rollup(deptno,job)" grouping (deptno) returns 0. You get different results; therefore the order does matter.
Does the column sequence in group by rollup decides the returning of grouping(deptno) function...Yes.
"GROUP BY ROLLUP (deptno, job)" means a superaggregate row for each value of job, representing all deptnos, will be formed. That is, you will get one row representing all analysts; another row representing all clerks, another row representing all managers, and so on. This will be similar to the results that you would get if you never mentioned the first expression in the ROLLUP list, that is, deptno. You will not get a superaggregate row representing any one deptno, say, 10.
"GROUP BY ROLLUP (job, deptno)" means a superaggregate row for each value of deptno, representing all jobs, will be formed. That is, you will get one row representing all anlysts; another row representing deprtment 10, another row representing department 20, and so on. This will be similar to the results that you would get if you never mentioned the first expression in the ROLLUP list, that is, job. You will not get a superaggregate row representing any one job, say, 'ANALYST'.
Maybe you are looking for
-
Creative ALchemy Guide and FAQ
Hi everyone,? I have decided to include this for the benefit of those who are new. Creative ALchemy al-che-my [al-kuh-mee] ~ any magical power or process of transmuting a common substance, usually of little value, into a substance of great value. - D
-
2008.007 Security Update Will Not Boot - 2 different MacBooks
I installed the 2008.007 update on a 15" first gen MacBook Pro and an 11 month old 17" Santa Rosa 2.4ghz MacBook Pro today. Both rebooted successfully the first time and we could login but on a reboot or second user login we got a peculiar blank blue
-
Error when opening attachment in DRL Document
Hello all, I am working on giving read access to DRL for a specific group of people. I have been able to allow them to see the entire taxonomy of the DRL. When they try to access the attachment in the document they get an error message. Any suggestio
-
My ipad screen starts white and cloudy
My IPad screen is white and cloudy particularly around the edges but starts to clear over about 5 minutes of playing. Any thoughts on how I can restore the screen to its original clarity?
-
OSX will not remember WPA selection
Our wireless network requires 802.1X authentication and is running both WPA and WPA2. I have configured the network and internet connection settings to use WPA because OS X will not request an IP address via DHCP with WPA2 (it will connect and authen