Home > Software design >  SQL or function
SQL or function

Time:02-17

In SQl its common to take the SUM of all values from a column

SELECT SUM(column_name)
FROM table_name
WHERE condition;

Can the same thing be done but instead of summing each value in an attribute, each value is "OR'd" together? This would only work if the attribute was boolean of course

CodePudding user response:

MAX(booleancolumn) will return OR'd together.

(Since TRUE > FALSE.)

CodePudding user response:

There are two challenges here:

  1. SQL doesn't have boolean type
  2. This isn't part of any of the built-in aggregate functions.

However, some databases will allow you to define your own functions, including aggregate functions. So it is at least possible.

  •  Tags:  
  • sql
  • Related