Most interesting SQL snippets from SQLize.online with comments
0 Following
12 posts

Find items presents in each category in many-to-many relation

Assume we have 3 tables items, categories and item_categories where stored records about items, categories and relations between them

How to find anomaly in sequence

Assume we have table with integer column. How we can find is all values of this column are sequence without gaps or duplicates.

Calculate transactions rolling balance with max limit

One more case using CTE (common table expressions). Assume we have table of financial transactions like posted below, where Id is transaction identifier integer auto increment without gaps, Type is D for deposits and W for withdrawals

How to find records where text field does not contains digits?

MySQL solution (using rlike):

How to calculate average value from json array (PostgreSQL)

Assume we have table stored values within json array. For example:

How to remove duplicates from one column table?

Let we have some one table contains duplicates values:

Find records from table where changed value of one of columns

For example we have table with customer loan applications, where each customer provide count of child. For simplify task let it be table with 2 columns: name and childs

How to check MS SQL Server version?

Question: What are the possible ways to determine the deployed SQL Server version?

How to get user last activity record?

Data: user_activity

How to aggregate data in JSON format?