Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

sql
communitycreator
math

What is SIGN() in SQL?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The SIGN() function returns the sign of a number. Specifically, SIGN() returns -1 for a negative value, 1 for a positive value, and 0 for zero.

Figure 1 shows a visual representation of the SIGN() function:

Figure 1: Visual representation of the SIGN() function

Syntax

SIGN(number)

Parameter

The SIGN() function requires a number as a parameter.

Return value

SIGN() returns the sign of a number sent as a parameter:

  • -1 for a negative value parameter, which symbolizes a negative sign.
  • 1 for a positive value parameter, which symbolizes a positive sign.
  • 0 for a parameter of zero.

Example

/*example showing how to use SIGN(X)*/
-- positive number
select SIGN(4);
-- negative number
select SIGN(-6.6);
-- zero
select SIGN(0);

RELATED TAGS

sql
communitycreator
math

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring