首页 > 解决方案 > SuiteQL cannot includes keyword 'DISTINCT'?

问题描述

I keep on getting an error when I try to use the distinct keyword with SuiteQL.

This is my code:

var bannedItemIdArr = [];
var querySQL = "SELECT DISTINCT item.ID AS idRAW /*{id#RAW}*/ FROM item, (SELECT itemMember.parentitem AS parentitem, itemMember.parentitem AS parentitem_join, itemMember.ID AS ID, item_0.itemtype AS itemtype, itemMember.item AS item, item_0.itemtype AS itemtype_crit, item_0.isinactive AS isinactive_crit FROM itemMember, item item_0 WHERE itemMember.item = item_0.ID(+)) itemMember_SUB WHERE item.ID = itemMember_SUB.parentitem(+) AND ((UPPER(item.itemtype) IN ('ASSEMBLY') AND UPPER(itemMember_SUB.itemtype_crit) IN ('INVTPART', 'ASSEMBLY') AND itemMember_SUB.isinactive_crit = 'T' AND NVL(item.isinactive, 'F') = 'F'))";
var myPagedResults = query.runSuiteQLPaged({ query: querySQL, pageSize: 1000, });

The error:

Search error occurred: Invalid or unsupported search

How can I solve this error?

标签: sqlnetsuitesuitescript

解决方案


你看过query.Aggregate吗?

枚举描述 模块
保存 N/query 模块支持的聚合函数的字符串值。聚合函数对列或条件值执行计算并返回单个值。此枚举中的每个值(除了 MEDIAN)都有两个变体:distinct(使用 _DISTINCT 后缀)和 nondistinct(不使用后缀)。该变体确定聚合函数是对重复值的所有实例还是仅对值的单个实例进行操作。例如,考虑使用 MAXIMUM 聚合函数来确定一组值的最大值的情况。使用不同变体 (MAXIMUM_DISTINCT) 时,聚合函数会考虑重复值的每个实例。因此,如果这组值包含三个不同的值,它们都相等并且都表示集合中的最大值,聚合函数列出了所有三个实例。使用非显着变体 (MAXIMUM) 时,仅列出最大值的一个实例,而不管集合中该最大值的实例数。此枚举用于将聚合函数参数传递给 Component.createColumn(options)、Component.createCondition(options)、Query.createColumn(options) 和 Query.createCondition(options)。 N/查询模块

价值观

价值 描述
平均 计算平均值。
AVERAGE_DISTINCT 计算平均不同值。
数数 计算结果的数量。
COUNT_DISTINCT 计算不同结果的数量。
最大 确定最大值。如果值是日期,则确定最近的日期。
MAXIMUM_DISTINCT 确定最大不同值。如果值是日期,则确定最近的日期。
中位数 计算中值
最低限度 确定最小值。如果值是日期,则确定最早的日期。
MINIMUM_DISTINCT 确定最小不同值。如果值是日期,则确定最早的日期。
添加所有值。
SUM_DISTINCT 添加所有不同的值。

句法

// Add additional code
...
var myTransactionQuery = query.create({
    type: query.Type.TRANSACTION
});

var myAggColumn = myTransactionQuery.createColumn({
    fieldId: 'amount',
    aggregate: query.Aggregate.AVERAGE
});

myTransactionQuery.columns = [myAggColumn];
...
// Add additional code

推荐阅读