首页 文章

突出显示NetSuite保存的搜索中的重复值

提问于
浏览
2

我正在寻找一种方法来突出NetSuite保存的搜索中的重复项 . 重复项位于名为“ACCOUNT”的列中,该列填充了文本值 .

NetSuite允许使用精简版SQL Server向搜索添加字段(列) . 它还允许使用相同的代码对整行进行条件突出显示 . 但是,我没有看到比较数据行之间的值的明显方法 .

虽然重复项可以在摘要报告中组合在一起,并通过2或更多的计数进行标识,但我希望分别显示重复的行并突出显示每个行 .

我发现最接近的是一个聪明的公式来计算一个总计here

sum/* comment */({amount})
 OVER(PARTITION BY {name}
 ORDER BY {internalid}
 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)

我想知道是否可以通过检查重复项的字段对结果进行排序,并调整此代码以识别行和上一行之间的“ACCOUNT”字段中的更改 .

有任何想法吗?谢谢!

1 回答

  • 1

    This post has been edited. I have left the progression as a learning experience about NetSuite.

    Original - plain SQL way - not suitable for NetSuite

    这样的事情能满足您的需求吗?测试数据假定在id1和id2上查找重复项 . Note: This does not work in NetSuite as it supports limited SQL functions. See comments for links.

    declare @table table (id1 int, id2 int, value int);
    
    insert @table values
    (1,1,11),
    (1,2,12),
    (1,3,13),
    (2,1,21),
    (2,2,22),
    (2,3,23),
    (1,3,1313);
    --select * from @table order by id1, id2;
    
    select  t.*,
            case when dups.id1 is not null then 1 else 0 end is_dup     --identify dups when there is a matching dup record
    from    @table t
    left    join (  --subquery to find duplicates
            select  id1, id2
            from    @table
            group   by id1, id2
            having count(1) > 1
            ) dups
            on  dups.id1 = t.id1
            and dups.id2 = t.id2
    order   by t.id1, t.id2;
    

    First Edit - NetSuite target but in SQL.

    这是一个基于问题中提供的示例可用语法的SQL测试,因为我没有NetSuite进行测试 . 这将使用类似的语法在每个重复行上为您提供大于1的值 . Note: This will give the appropriate answer but not in NetSuite.

    select  t.*,
            sum(1) over (partition by id1, id2)
    from    @table t
    order   by t.id1, t.id2;
    

    Second Edit - Working NetSuite version

    经过一番来回,这是一个在NetSuite中运行的版本:

    sum/* comment */(1) OVER(PARTITION BY {name})
    

    这也将在任何重复行上给出大于1的值 .

    Explanation

    这通过将分区中包含的每一行的值1相加来工作 . 分区列应该是您认为重复的 . 如果只有一列重复(例如用户ID),则按上述方式使用 . 如果多个列重复(例如,名字,姓氏,城市),则在分区中使用逗号分隔列表 . SQL基本上按分区对行进行分组,并在 sum/* comment */(1) 中添加1 . 问题中提供的示例总结了实际列 . 通过求和1而不是当分区中只有1个ID时,我们将获得值1 . 任何更高的东西都是重复的 . 我想你可以把这个字段称为重复计数 .

相关问题