Skip to content
Advertisement

Tag: postgresql

Default value in select – SQL

I want to select the sum of the biggest and the lowest numbers in specific column of table, I get it well but I also need to set a default value in case if the column is empty, so far I tried this: And if my table is empty I want to get a single value with default value like

Percentage distribution of column occurence?

I am looking for a way to calculate the distribution of column values in my table. e.g. if I have two rows containing “red” and “blue”, each should have 50%. I want to count the occurence of col and compare that to the overall amount of rows. My attempt: Any help? Thank you! Answer Just pay attention to integer division.

Names of nodes at depth d for every descendant leaf

I have a category hierarchy that products are attached to. That category hierarchy is saved as an adjacency list. Products can be attached to any category nodes at any level. The category hierarchy is a tree. I would like to… get the name of every level 3 category… per product… where that product is attached to any level 3 category

Advertisement