I want a generic query to get fill rate of all columns in table .Query should work irrespective of the column number.I have to implement this using presto sql.I have tried searching for a method but nothing seems to working.
Input
| A | B | C | D |
|---|---|---|---|
| 1 | null | null | 1 |
| 2 | 2 | 3 | 4 |
| Null | Null | Null | 5 |
Output
| A | B | C | D |
|---|---|---|---|
| 0.66 | 0.33 | 0.33 | 1.0 |
Explanation: A Col contains 3 rows with 2 non null values so 2/3 B and C Cols contain 2 null value and one non null value so 1/3 D col there is no null values so 3/3
Thanks in advance
AFAIK Presto/Trino does not provide dynamic query execution capabilities (i.e. something like EXEC in T-SQL) so the only option (unless you are ready to go down user defined function road) to write a query which will enumerate all needed columns (if you are using client from another language - you can build the query dynamically leveraging
information_schema.columnsinfo):Output: