Home > Software engineering >  Any aggregate functions that allow DISTINCT *?
Any aggregate functions that allow DISTINCT *?

Time:08-26

Some functions allow the * notation in an aggregation function, such as:

SELECT COUNT(*) FROM sales

And other functions allow a DISTINCT modifier within the function call, such as:

SELECT COUNT(DISTINCT IF(x > 0, x, NULL)) FROM sales

My question is if any functions allow for the notation of:

SELECT function(DISTINCT *)

CodePudding user response:

No, except for the specific case of COUNT(), you can't use * in function arguments.

  • Stored functions take a fixed number of arguments.

  • Some built-in functions (for example, CONCAT() or COALESCE()) take a variable number of arguments, but you must spell them out when you call the function.

I looked in the parser code for MySQL, and found these cases of the use of the '*' symbol:

  • COUNT(*) or COUNT(ALL *) or COUNT(DISTINCT *)
  • SELECT * ... or SELECT ident.* ...
  • DELETE * ...
  • INSERT INTO ident (ident.*) ...
  • SHOW COUNT(*) WARNINGS or SHOW COUNT(*) ERRORS
  • GRANT ... ON * or GRANT ... ON ident.* or GRANT ... ON *.*
  • Arithmetic multiplication operator
  • Related