FetchXML and Aggregate Functions (multiple datasets if necessary)
In fetch xml,
How do I do conduct aggregate functions (most recent, sum, average) on retrieved columns, based on matches with another column.
let's say column a has a value of "Timothy."
How do I then find the total number of column b that also have a value of 'Timothy?'
But then the next value of column a is 'John.'
I would then want to display the total number of column b that have a value of 'John?'
If this is totally impossible, could introducing another dataset help?
Sql is not available here and fetchxml can only do so much. So this is going to have to be done with variables in the actual report.
Looks like you're using Dynamics CRM. If that being the case, you may be better off posting in MS Dynamics forums. This forum is specifically for Reporting Services and Power view
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page
Similar Messages
-
Analytic function and aggregate function
What are analytic function and aggregate function. What is difference between them?
hi,
Analytic Functions :----------
Analytic functions compute an aggregate value based on a group of rows. They differ from aggregate functions in that they return multiple rows for each group. The group of rows is called a window and is defined by the analytic_clause. For each row, a sliding window of rows is defined. The window determines the range of rows used to perform the calculations for the current row. Window sizes can be based on either a physical number of rows or a logical interval such as time.
Analytic functions are the last set of operations performed in a query except for the final ORDER BY clause. All joins and all WHERE, GROUP BY, and HAVING clauses are completed before the analytic functions are processed. Therefore, analytic functions can appear only in the select list or ORDER BY clause.
Analytic functions are commonly used to compute cumulative, moving, centered, and reporting aggregates.
Aggregate Functions :----------
Aggregate functions return a single result row based on groups of rows, rather than on single rows. Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database divides the rows of a queried table or view into groups. In a query containing a GROUP BY clause, the elements of the select list can be aggregate functions, GROUP BY expressions, constants, or expressions involving one of these. Oracle applies the aggregate functions to each group of rows and returns a single result row for each group.
If you omit the GROUP BY clause, then Oracle applies aggregate functions in the select list to all the rows in the queried table or view. You use aggregate functions in the HAVING clause to eliminate groups from the output based on the results of the aggregate functions, rather than on the values of the individual rows of the queried table or view.
let me know if you are feeling any problem in understanding.
thanks.
Edited by: varun4dba on Jan 27, 2011 3:32 PM -
Any difference between distinct and aggregate function in sql query cost???
Hi,
I have executed many sql stmts patterns- such as:
a) using a single table
b) using two tables, using simple joins or outer joins
but i have not noticed any difference in sql stmts in cost and in execution plan....
Anyway, my colleague insists on that using aggregate function is less costly compared to
distinct....(something i have not confirmed, that's why i beleive that they are exactly the same...)
For the above reffered 1st sql pattern.. we could for example use
select distinct deptno
from emp
select count(*), deptno
from emp
group by deptno select distinct owner, object_type from all_objects
select count(*), owner, object_type from all_objects
group by owner, object_typeHave you found any difference between the two ever...????
Note: I use Ora DB 10g v2.
Thank you,
Simdistinct and aggregate function are for different uses and may give same result but if u r using aggregate function to get distinct records, it will be expensive...
ex
select distinct deptno from scott.dept;
Statistics
0 recursive calls
0 db block gets
2 consistent gets
0 physical reads
0 redo size
584 bytes sent via SQL*Net to client
488 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
4 rows processed
select deptno from scott.emp group by deptno;
Statistics
307 recursive calls
0 db block gets
60 consistent gets
6 physical reads
0 redo size
576 bytes sent via SQL*Net to client
488 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
3 rows processed
Nimish Garg
Software Developer
*(Oracle & ASP.NET)*
Indiamart Intermesh Limited, Noida
To Get Free Oracle & ASP.NET Code Snippets
Follow: http://nimishgarg.blogspot.com -
Need complex query with joins and AGGREGATE functions.
Hello Everyone ;
Good Morning to all ;
I have 3 tables with 2 lakhs record. I need to check query performance.. How CBO rewrites my query in materialized view ?
I want to make complex join with AGGREGATE FUNCTION.
my table details
SQL> select from tab;*
TNAME TABTYPE CLUSTERID
DEPT TABLE
PAYROLL TABLE
EMP TABLE
SQL> desc emp
Name
EID
ENAME
EDOB
EGENDER
EQUAL
EGRADUATION
EDESIGNATION
ELEVEL
EDOMAIN_ID
EMOB_NO
SQL> desc dept
Name
EID
DNAME
DMANAGER
DCONTACT_NO
DPROJ_NAME
SQL> desc payroll
Name
EID
PF_NO
SAL_ACC_NO
SALARY
BONUS
I want to make complex query with joins and AGGREGATE functions.
Dept names are : IT , ITES , Accounts , Mgmt , Hr
GRADUATIONS are : Engineering , Arts , Accounts , business_applications
I want to select records who are working in IT and ITES and graduation should be "Engineering"
salary > 20000 and < = 22800 and bonus > 1000 and <= 1999 with count for males and females Separately ;
Please help me to make a such complex query with joins ..
Thanks in advance ..
Edited by: 969352 on May 25, 2013 11:34 AM969352 wrote:
why do you avoid providing requested & NEEDED details?I do NOT understand what do you expect ?
My Goal is :
1. When executing my own query i need to check expalin plan.please proceed to do so
http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_9010.htm#SQLRF01601
2. IF i enable query rewrite option .. i want to check explain plan ( how optimizer rewrites my query ) ? please proceed to do so
http://docs.oracle.com/cd/E11882_01/server.112/e16638/ex_plan.htm#PFGRF009
3. My only aim is QUERY PERFORMANCE with QUERY REWRITE clause in materialized view.It is an admirable goal.
Best Wishes on your quest for performance improvements. -
Self Join and Aggregate Functions
Hi all,
I am trying a query in TOAD where I need to use an aggregate function MAX and a self join using a subquery. Its working fine when there is no aggregate function but when I tried to use the MAX function then its running for infi time. Is it because of the invalid joins? or because of the usage of the self join and aggregate func?
The query contains some other tables too....
Any one please help....
Thanks in advance,
GToad will bring back a limited set of rows and present them to you giving the impression that the work is done. Adding an aggregate function requires the entire resultset to be traversed.
Yes, post the 2 queries to verify what I am saying. -
SQL query using Group by and Aggregate function
Hi All,
I need your help in writing an SQL query to achieve the following.
Scenario:
I have table with 3 Columns. There are 3 possible values for col3 - Success, Failure & Error.
Now I need a query which can give me the summary counts for distinct values of col3 for each GROUP BY of col1 and col2 values. When there are no values for col3 then it should return ZERO count.
Example Data:
Col1 Col2 Col3
abc 01 success
abc 02 success
abc 01 success
abc 01 Failure
abc 01 Error
abc 02 Failure
abc 03 Error
xyz 07 Failure
Required Output:
c1 c2 s_cnt F_cnt E_cnt (Heading)
abc 01 2 1 1
abc 02 1 1 0
abc 03 0 0 1
xyz 07 0 1 0
s_cnt = Success count; F_cnt = Failure count; E_cnt = Error count
Please note that the output should have 5 columns with col1, col2, group by (col1,col2)count(success), group by (col1,col2)count(failure), group by (col1,col2)count(error)
and where ever there are NO ROWS then it should return ZERO.
Thanks in advance.
Regards,
ShivaHi,
user13015050 wrote:
Thanks TTT. Unfortunately I cannot use this solution because I have huge data for this.T's solution is basically the same as mine. The first 23 lines just simulates your table. Since you actually have a table, you would start with T's line 24:
SELECT col1 c1, col2 c2, SUM(decode(col3, 'success', 1, 0)) s_cnt, ...
user13015050 wrote:Thanks a lot Frank. It helped me out. I just did some changes to this as below and have no issues.
SELECT col1
, col2
, COUNT ( CASE
WHEN col3 = 'SUCCESS'
THEN 1
END
) AS s_cnt
, COUNT ( CASE
WHEN col3 = 'FAILED'
THEN 1
END
) AS f_cnt
, COUNT ( CASE
WHEN col3 = 'ERROR'
THEN 1
END
) AS e_cnt
FROM t1
WHERE c2 in ('PURCHASE','REFUND')
and c4 between to_date('20091031000000','YYYYMMDDHH24MISS') AND to_date('20100131235959','YYYYMMDDHH24MISS')
GROUP BY c1, c2
ORDER BY c1, c2;
Please let me know if you see any issues in this query.It's very hard to read.
This site normally compresses spaces. Whenever you post formatted text (such as queries or results) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
Also, post exactly what you're using. The code above is SELECTing col1 and col2, but there's no mention of either in the GROUP BY clause, so I don't believe it's really what you're using.
Other than that, I don't see anything wrong or suspicious in the query. -
Can Window and aggregate functions be used in Pro*C?
Are Window functions like dense_rank() over (partition by ... order by ..) available in Pro*C embedded SQL?
Thanks
Rawender GuronPlease refer to this thread: "Is this forum also used for Pro*'C Questions? "
Is this forum also used for Pro*'C Questions? -
Below expression works fine with text box but gives error in dataset expression.
="SET FMTONLY OFF select "+ join(Parameters!Column.Value,",") +" FROM pamcustom.dbo.vw_HFL_HFD_HotfileData INNER JOIN pamcustom.dbo.HFL_HFB_HotFileBatch on BatchID = HFB_intBatchID where BatchID ="+Parameters!BatchId.Value+"
and "+Parameters!cmbTranType.Value+" "+ iif(CountRows("DS_Aml_Mnr_Iss_Desc")=Parameters!Mnr_Iss_Desc.count," "," and aml_mnr_iss_desc in "+"('" & join(Parameters!Mnr_Iss_Desc.Value,"','")
& "')")+iif(CountRows("ds_ReportingCategory")=Parameters!ReportingCategory.count," "," and ReportingCategory in "+"('" & join(Parameters!ReportingCategory.Value,"','") & "')")+iif(CountRows("ds_NAICSubGroup")=Parameters!NAICSubGroup.count,"
"," and naicsubgroup in "+"('" & join(Parameters!NAICSubGroup.Value,"','") & "')")+iif(CountRows("ds_PortTrading")=Parameters!PortTrading.count," "," and porttrading in "+"('"
& join(Parameters!PortTrading.Value,"','") & "')")+iif(CountRows("ds_GL_LE")=Parameters!GL_LE.count," "," and gl_le in "+"('" & join(Parameters!GL_LE.Value,"','") &
"')")+iif(CountRows("ds_coagroup")=Parameters!cmbCoaGrp.count," "," and coagroup in "+"('" & join(Parameters!cmbCoaGrp.Value,"','") & "')")+iif(CountRows("Portfolio")=Parameters!cmbPort.count,"
"," and portfolio in "+"('" & join(Parameters!cmbPort.Value,"','") & "')")+IIf(IsNothing(Parameters!txtSecID.Value)," "," and secid in ('"+Replace(Parameters!txtSecID.Value,",","','")+"')")+iif(IsNothing(Parameters!minPortFilter.Value)
and IsNothing(Parameters!MinPort.Value)," "," and portfolio "+Parameters!minPortFilter.Value+Parameters!MinPort.Value)+iif(IsNothing(Parameters!maxPortFilter.Value) and IsNothing(Parameters!MaxPort.Value)," ","
and portfolio "+Parameters!maxPortFilter.Value+Parameters!MaxPort.Value)+iif(IsNothing(Parameters!minCoaFilter.Value) and IsNothing(Parameters!txtMinCoa.Value)," "," and portfolio "+Parameters!minCoaFilter.Value+Parameters!txtMinCoa.Value)+iif(IsNothing(Parameters!maxCoaFilter.Value)
and IsNothing(Parameters!txtMaxCoa.Value)," "," and portfolio "+Parameters!maxCoaFilter.Value+Parameters!txtMaxCoa.Value)
I guess the error " Aggregate and lookup functions cannot be used in query parameter expressions." is because I am using CountRow to ensure that if all values of multi select all selected i will not use that filter in where clause.
Pls. guide...Hi, Include your parameter total count in the dataset for parameter and instead of using countrows() function use the count from dataset in the expression.
Hope this helps.........
Ione -
Crystal Reports and connecting to multiple tables in a dataset - I'm Going Crazy!!
This is my first application, first report and first everything. Wouldn't you know the report I am trying to produce is probably more difficult!! What is happening is that I have a form(screen) up in my application with the information displayed on it from a recrod in a table that I want to put on a report to be view and/or printed and eventually down the road I want to incorporate a signature. One step at a time though, here is what I have accomplished. I have created the report, I have gotten it to display in the viewer but it will not push the data from the table that I want displayed. It only displays the text that I have typed on the form. This is a Visual Basic application created in Visual Studio 2005 using a SQL database. If you need more information then just ask and I will try to fumble through and tell you what I know. (Oh and to top it off............I am also trying to get information to display from other tables also (codes connected to descriptions etc.))
Any help would be really appreciated as I have went through tutorials, read white papers, tech notes and anything else I can find but I just can't get it to work!!
Thanks!You do need to give more information. To better help, we would need to know the database, when you say SQL do you mean SQL Server, how you created the dataset, whether there are multiple tables in a single dataset or multiple datasets, etc.
The report appears to be running so the underlying issue as you know will likely be the dataset. You may want to confirm the dataset does in fact have data in it. Returning a simple count will let you know there are rows. If you used the components rather than code to create the objects you can also see the data returned in the fill process.
Once you know you have data in the dataset, you can check your reports connection to the dataset.
Just hang in there... the problem is probably a simple fix. I am sure others will follow on with more suggestions.
Regards,
John W. -
How to create multiple reports and dashboards from one dataset?
Hi there,
I've centralized the data to an excel workbook from multiple data sources and added as a dataset to my new Power BI site. How can I build multiple reports and dashboards out of one dataset?Hi Kuber,
In the Datasets section on the Navigation pane (left side of your Dashboards page), you can click "..." next to each dataset. One of the options in the contextual menu is Explore. When you explore a dataset, you can create reports and save
them.
You can find more about this and other topics in our Getting Started content:
https://go.microsoft.com/fwlink/?LinkID=512054
Thanks,
M. -
Aggregate functions and normal function in SELECT statement
hi
i am using MS Access DataBase ...
i have lot of integer coloumns in my Database
i want to retrieve the coloumn values as well as the min , max and avg of that coloumn
i dont know whether its possible to do in a single statement or not
generally if we retrieve the values of a particular coloum
we say " SELECT length FROM TABLENAME WHERE somecondition"
and then get the values as int len = rs.getInt("length")..... over a loop
but how to retieve the value of an aggregate function?
like if i say "SELECT avg(colname),max(colname),min(colname) FROM TABLENAME WHERE somecondition"
how do i retrieve this value ???
i dont know if its possible or not ....pls help.........Give names too each column
SELECT avg(colname) average,max(colname) max,....
and then rs.getInt("average")
This works in Oracle and Sybase, not sure on MS access tough -
Database Aggregate Functions and Oracle Discoverer
Hello Guys.
There are a lot of aggregate function inside the database, unfortunatelly some of them are not directly accesible from Oracle Discoverer.
For example :
STATS_BINOMIAL_TEST
STATS_CROSSTAB
STATS_F_TEST
STATS_KS_TEST
STATS_MODE
STATS_MW_TEST
STATS_ONE_WAY_ANOVA
STATS_T_TEST_*
STATS_WSR_TEST
What is the best way to incorporate this kind of function in Oracle Discoverer ?
Thanks
Ramiro Ortiz RiosWhile Discoverer today is unable to recognize these Oracle Database functions, we are looking at adding this capability into the product. If you think this is important, please take the poll at http://oraclebi.blogspot.com/2006/04/must-have-in-discoverer.html
Also, if you can spare a few minutes, do send me a mail at abhinav.oracle at gmail.com with a brief description of a use case that describes where and how these functions would be used.
Thanks
Abhinav
Oracle Business Intelligence Product Management
BI on Oracle: http://www.oracle.com/bi/
BI on OTN: http://www.oracle.com/technology/products/bi/
Documentation: http://docs.oracle.com/
Oracle BI Suite EE: http://www.oracle.com/technology/products/bi/enterprise-edition.html
Oracle BI Suite SE: http://www.oracle.com/technology/products/bi/standard-edition.html
Oracle BI Suite SE One: http://www.oracle.com/technology/products/bi/standard-edition-one.html
Discoverer: http://www.oracle.com/technology/products/discoverer/
BI Software: http://www.oracle.com/technology/software/products/ias/devuse.html
BI Blog: http://oraclebi.blogspot.com/
Blogs: http://blogs.oracle.com/ -
Selecting both a aggregate function and another field
I am trying to do something very simple but I am not sure of the syntax.
I would like to select all of the petid's and find the count of the pets in a given city, both from the same table, Pets.
Can somebody please help me with this?
ThanksHi,
An aggregate function will give you one row of output per group.
For example, if you use the aggregate COUNT function to get the total number of rows in a whole table, then you can only have one row of output, representing the whole table, so, if I understand the problem, you can't (easily) use an aggregate function.
Almost all of the aggregate functions have analytic counterparts, that can produce the same results without collapsing the result set into one row per group.
I think this is what you requested:
SELECT petid
, COUNT (*) OVER (PARTITION BY 1) AS total_cnt
FROM pets
WHERE city = 'Paris' -- or whatever
;Sorry, I'm not at a database now, so I can't check, but I think you don't need the PARTITION BY clause, so you can also say:
, COUNT (*) OVER () AS total_cntThe keyword OVER marks this as an analytic, rather than an aggregate, function. -
How to write SQL query and apply aggregate functions on it
Hello experts,
Iu2019ve a task to write SQL query on tree tables and do inner join on them. Iu2019ve accomplish this task by using T-CODE SQVI. However now I need to write a query and apply SQL functions on it i.e. Add, Count, Max and Min etc. Please can someone tell me how I can write SQL query with aggregate functions in SAP?
Thanks a lot in advanceHI Mr. Cool
you can see the below code for using aggregate functions.
where ARTIST and SEATSOCCU are the field names for which you want to perform these functions.
DATA: TOTAL_ENTRIES TYPE I,
TOTAL_ATT TYPE I,
MAX_ATT TYPE I,
AVG_ATT TYPE I.
SELECT COUNT( DISTINCT ARTIST )
SUM( SEATSOCCU )
MAX( SEATSOCCU )
AVG( SEATSOCCU ) FROM YCONCERT INTO (TOTAL_ENTRIES, TOTAL_ATT,
MAX_ATT, AVG_ATT).
Thanks
Lalit Gupta -
OracleDataAdapter and multiple datasets
Hello
I'd like to ask, does each dataset need its own data adapter? I'm implementing application which has a lot of datagridviews, and I wonder how to use adapter. Is it possible to have two datasets and use following scenario: fill first dataset, bind it to datagridview, then using the same adapter fill second dataset and bind it to datagridview, and after then call adapter.update for first dataset and then for second dataset - all using only one adapter. Is it possible or not?
Thanks for advice.does each dataset need its own data adapter?no
Is it possible to have two datasets and use following scenario:
fill first dataset, bind it to datagridview, then using the same adapter
fill second dataset and bind it to datagridview, and after then call
adapter.update for first dataset and then for second dataset -
all using only one adapter. Is it possible or not?yes
Cheers,
NH
Maybe you are looking for
-
Open DNS vs TWC DNS (Dallas)
Should I use an open DNS or stay with TWC DNS (Dallas, TX)? Are there really benefits to speak of as a second year Computer Engineering student? Thanks all.
-
Epson Inkjets -- horrible quality printouts, missing colors w/ Tiger 10.4.3
Ever since the updates to Tiger 10.4, my Epson Stylus C82 inkjet (which has worked perfectly for the past three years) will no longer print all four colors. I'm lucky if I can even get a b/w text print that isn't spotty and missing bands of ink all t
-
please help I have to update my clients site tonight I have been using muse subscription since Nov 19, 2012 An unexpected error occurred.An unexpected error occurred processing your request. Please try again later.I-2
-
Safari crashes with message about "ct_plugins"
Safari now crashes instantly, every single time. It gives me a message saying that the crash was probably caused by "ct_plugins." I cannot find anything called "ct_plugins" by using the Finder. Remarkably unhelpful. Actually reminds me of the old day
-
Hi, So I have really struggled with embracing FCP X. Though each update seems to make things a little bit better, I really still just dispise the whole layout of X and despite the background rendering, it seems unbelievably slow on my setup compared