I have a table with 100 columns.
It happens that I want the query to show only the columns that have "value <> 0"
So the column that has val = 0 should not be displayed.
Can anyone help with this
I have a table with 100 columns.
It happens that I want the query to show only the columns that have "value <> 0"
So the column that has val = 0 should not be displayed.
Can anyone help with this
You can have a query like the following:
SELECT FLOOR(SUM(IF(column1 IN (0),0,1))/COUNT(*)),FLOOR(SUM(IF(column2 IN (0),0,1))/COUNT(*)),...,FLOOR(SUM(IF(column100 IN (0),0,1))/COUNT(*)) FROM table_name
This will give you a row with column value = 0 if the column contains 0 and 1 if column contains no 0.
You cannot adjust the number of columns returned. That is defined by a projection (your SELECT block) and a projection is evaluated against the table schema. It is expected that you know the number of columns and the types that you want returned in a projection.
As the previous user had mentioned, you can use a function or case statement to change the value in the column, or alternatively, you can restrict the rows returned with the WHERE clause (if some value or values are <> 0, for example).
The schema of the generated projection table returned must be static though.