[HANA] [eighth series of articles] SAP HANA XS query using Data Services CDS entity [two]

No public: SAP Technical
Author: Matinal
 

 

The preface

We can focus on my public number, the number public in the layout better, read more comfortable.

Body part

Connect one, continue

7, the result set using conditions. WHERE you can use $ () method to set the limits of the query result set returned. The following example shows how to select all items equal to its net net orders for half (or more).

​
var qSelectedOrders =
 qOrderAndItemTitles.$where(soHeader.items.NETAMOUNT.
$div(soHeader.NETAMOUNT).$gt(0.5)) 

​

References to such fields and the associated items such as attributes of the entity constructor, e.g. soHeader.items. As in the case of the associated projection (Projections) is, XSDS conditions will automatically generate all the necessary reference JOIN, even though they are not a part of this projection (Projections) a. To create more complex expressions in $ in. See, API described earlier.

 

8, the query refinement for a particular match mode.

Syntax $ matching () method, you can use $ find () and $ findAll () method of class JSON format to specify the conditional expression. The following sample code shows how to further optimize the selection result set returned, for example, accepts only Euro currency and amount of data that is greater than 2.

​
qSelectedOrders = qSelectedOrders.$matching({
 items: {
 CURRENCY: 'EUR',
 QUANTITY: {
 $gt: 2
 }
 }
});

​

9, any value added to the result set.

 

Can $ addFields () method to add any value to calculate the result set. The following example shows how to query the number of days since the delivery of the project through the sale.

​
qSelectedOrders = qSelectedOrders.$addFields({
 "DaysAgo": soHeader.items.DELIVERYDATE.$prefixOp("DAYS_BETWEEN", new
Date())
});

​


10, having calculated using a polymerization field.

 

The summary is $ addFields () operator with an additional $ Aggregate () method of the special case of a combined field calculation. The following example shows the average number and product ID before retrieving 100 sales order ID.

​
var qAverageQuantity = soItem.$query().$limit(100).$aggregate({
 SALESORDERID: true,
 PRODUCTID: true
}).$addFields({
 averageQuantity: soItem.QUANTITY.$avg()
});

​

If you need more restrictive projection, it may be replaced in the $ Aggregate false calls, as shown in the following example, the sales order to delete the ID of the result set.

​
var qAverageQuantity = soItem.$query().$limit(100).$aggregate({
 SALESORDERID: false,
 PRODUCTID: true
}).$addFields({
 averageQuantity: soItem.QUANTITY.$avg()
});

​

11, in the order specified in the result set.

 

In order to specify the result set, use $ Order () method, wherein the condition comprises a plurality of orders as a parameter. Each order contains a standard property "by" and a definition expression of the desired sequence. Alternatively, each may comprise a standard marker to claim desc $ and $ nullsLast descending flag. The following example uses two standard according to the net first header in descending order the result set and sequentially project the net result set is displayed.

​
qSelectedOrders = qSelectedOrders.$order({$by: soHeader.NETAMOUNT,
$desc:true},
 {$by: soHeader.items.NETAMOUNT});

​

12, concentrated delete duplicates from the result.

 

$ Distinct operator delete duplicates from the result set. The following example shows how to display a collection of all the currency used in the sales order.

​
var qAllCurrencies = soHeader.$query().$project({CURRENCY: true}).$distinct();

​

This is the end use to explain about SAP HANA XS query using Data Services CDS entity.

Guess you like

Origin www.cnblogs.com/SAPmatinal/p/11184366.html