DEV Community

Judy
Judy

Posted on

1 1 1 1 1

How to set duplicate content in a dataset to null with esProc

The first two fields of a certain database table may have duplicate values, such as the first three records below.

Image description
Now we need to change all duplicate values to null. In other words, after grouping by the first two fields (equivalent to grouping by one of the fields), only the first record in the group remains unchanged, and the first two fields of other records are changed to null.

The calculation result is as follows:

Image description

After SQL grouping, it must aggregate immediately, and the grouped subsets cannot be kept for further calculation. SQL also does not have natural row numbers within the group, making the code difficult to write.

esProc provides a rich set of calculation functions that can keep grouped subsets for further calculation, with natural row numbers, including row numbers within the group:

Try.DEMO

Image description
A1: Load data.

A2: Group by the first field using the group function, but do not aggregate.

Image description
Each group is a set that can be expanded by clicking, as shown in the first two groups.

Image description
A3: Use the run function to modify the data of each group. When the member’s index in the group is greater than 1, change the first two fields to null. ~ represents the current group, # represents the sequence number within the group.

Image description
A4: Merge the groups.

Image description
The step-by-step code above is beneficial for learning and debugging. Once proficient, A2-A4 can be combined into one statement:

=A1.group(Column_A).run(~.(if(#!=1,Column_A=Column_B=null))).conj()

Enter fullscreen mode Exit fullscreen mode

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!

Join the Runner H "AI Agent Prompting" Challenge: $10,000 in Prizes for 20 Winners!

Runner H is the AI agent you can delegate all your boring and repetitive tasks to - an autonomous agent that can use any tools you give it and complete full tasks from a single prompt.

Check out the challenge

DEV is bringing live events to the community. Dismiss if you're not interested. ❤️