Skip to content

Tag: sql

SQL – Flag rows till 0 value of each group

I am calculating a running balance and want to flag all rows till 0 value to have ‘MATCHED’ flag else ‘NOT-MATCHED’ flag with respect to account ID. Here is what I have tried but didn’t got proper result: Answer We can use a sub-query to find the last acct_rank which is 0 and the…

How should I use `json field` in where clause in postgresql?

I have a json field in postgresql table feeAmount: I’d like to query rows whose feeAmount -> value is not null. Some rows may be null for the entire feeAmount field. some rows’ feeAmount has a json data whose value is null. They need to be excluded. I have tried this query: but both of the quer…

SQL Optimization, Nested Query on the same table

i have to create a query that return employees having mutliple territories parent for the same function code : Table employee_territory_function Table territory the result must be the employee_id 12346 which have multiple parents my query was : The query takes much time execution with 10k for the couple ( emp…