How can I aggregate some tuples like this
COL_1 | COL_2 | COL_3 | COL_4 val | T | F | F val | F | T | F
with the OR function and return the following table?
COL_1 | COL_2 | COL_3 | COL_4 val | T | T | F
use the keyword COUNT to count the number of rows in a column or table. use the keyword AVG to find the mean of a numerical column. use the keyword SUM to find the total of a numerical column when all the values are added together. use the keyword GROUP BY to group by a column in a table.
SQL aggregation function is used to perform the calculations on multiple rows of a single column of a table. It returns a single value. It is also used to summarize the data.
FIRST and LAST are very similar functions. Both are aggregate and analytic functions that operate on a set of values from a set of rows that rank as the FIRST or LAST with respect to a given sorting specification. If only one row ranks as FIRST or LAST , the aggregate operates on the set with only one element.
An aggregate function can be used in a WHERE clause only if that clause is part of a subquery of a HAVING clause and the column name specified in the expression is a correlated reference to a group.
Simply do a GROUP BY
, use MAX()
to return T if available, else F.
select col_1, max(col_2), max(col_3), max(col_4) from tablename group by col_1
Just as a side note (doesn't work with Oracle): In PostgreSQL, you would do this:
SELECT col_1, bool_or(col_2), bool_or(col_3), bool_or(col_4) FROM tablename GROUP BY col_1 ORDER BY col_1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With