Skip to content
Advertisement

How do I derive a value for a column based on another column’s value?

I have a projects table like the one below. There are two slightly different id columns idx and idy–one idx can have multiple idys (for versioning).

The goal is to consolidate the usage such that for every idx, the result will have:

  • a use_count col which is SUM(use_count) for same idx
  • the latest usage_date
  • the name corresponding to the latest usage_date

Additionally, usage_date has to be within a certain range, but this hopefully is trivial.

So far, I’ve got

..but having trouble figuring out how to derive the latest name of the project (with id x1)

Advertisement

Answer

You can try below way –

DEMO

Output:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement