on 10-07-2013 7:24 AM
Hi All,
Is there anyway in SAP HANA OData Services to get count or distinct count ? eg. to achieve something of
select group_type, count(customer_id), sum(sales_price) from "SOME_TABLE" group by group_type;
Hi Hriday,
there is an URL parameter $count, which can be used to directly retrieve the size of an EntitySet or Association. Just use it like that:
Are you looking for something like this?
Best,
René
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Rene,
I've explored the $count, but thats not what I'm looking for. Let me give a proper example.
Group_Type | Customer_id | Amount |
---|---|---|
Group 1 | 1 | 10 |
Group 2 | 2 | 20 |
Group 3 | 3 | 20 |
Group 1 | 4 | 30 |
Group 1 | 5 | 30 |
Group 2 | 6 | 20 |
Group 3 | 7 | 10 |
Now when I'll run the query,
select group_type, count(customer_id), sum(sales_price) from "SOME_TABLE" group by group_type;
it will return something like
Group Type | Count(Customer_id) | Sum(Amount) |
---|---|---|
Group 1 | 3 | 70 |
group 2 | 2 | 40 |
Group 3 | 2 | 30 |
Hope this clears my doubt.
Thanks
Hriday
Hello Hriday,
Please find this section from the SAP HANA dev guide of SP06. (page 295)
Explicit Aggregation
The example for the explicit aggregation is based on the following table definition: sample.odata:revenues.hdbtable
table.schemaName = "ODATASAMPLES";table.tableType = COLUMNSTORE; table.columns = [ {name = "Month"; sqlType = INTEGER; nullable = false;}, {name = "Year"; sqlType = INTEGER; nullable = false;}, {name = "Amount"; sqlType = INTEGER; nullable = true;} ];table.primaryKey.pkcolumns = ["Month","Year"];
You can aggregate the columns of objects (without metadata) that are necessary for the derivation of aggregation by explicitly denoting the column names and the functions to use, as illustrated in the following example of a service definition: sample.odata:aggrexpl.xsodata
service { "sample.odata::revenues" as "Revenues" keys generate local "ID" aggregates always (SUM of "Amount"); }
The results of the entity set Revenues always contain the aggregated value of the column Amount. To extract the aggregated revenue amount per year, add $select=Year,Amount to your requested URI.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.