如何翻译此SQL查询:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value
到Acumatica BQL?
答案 0 :(得分:3)
我相信Bql还没有可用的功能。
我解决这个问题的方法是使用投影来生成子查询。例如:
[Serializable]
[PXProjection(typeof(
Select4<Table,
Aggregate<
GroupBy<Table.column1,
Sum<Table.column2>>>>))]
public class AggregateTable : IBqlTable
{
// This will contain aggregate value - GroupBy
public abstract class column1: PX.Data.IBqlField
{
}
[PXDBString(BqlField = typeof(Table.column1))]
[PXUIField(DisplayName = "Column1")]
public virtual string Column1 { get; set; }
// This will contain aggregate value - Sum
public abstract class column2: PX.Data.IBqlField
{
}
[PXDBInt(BqlField = typeof(Table.column2))]
[PXUIField(DisplayName = "Column2")]
public virtual int? Column2 { get; set; }
}
然后您可以使用正常的选择过滤聚合:
public PXSelect<AggregateTable, Where<AggregateTable.column2, Equal<Required<AggregateTable.column2>>>> FilteredTable;
var rows = FilteredTable.Select(10);
我试着非常谨慎地使用它,因为如果你不小心它可能会变得混乱。
答案 1 :(得分:1)
在FBQL中出现了Haveing。下面是实现了以下内容的AggregateTo <>和OrderBy <>部分的示例:
.AggregateTo<Sum<field1>, GroupBy<field2>, Max<field3>,
Min<field4>, Avg<field5>, Count<field6>>.
Having<field5.Averaged.IsGreater<Zero>>
.OrderBy<field1.Asc, field2.Desc, field3.Asc>