COT() Function in SQL

Last Updated : 9 Aug 2026

The SQL COT() function is used in trigonometric calculations, engineering applications, signal processing, antenna alignment, geographic analysis, graphics, and scientific data processing.

What is the COT() Function in SQL?

The COT() function is a mathematical function that is utilized to return the cotangent of a given angle in radians. The cotangent is the reciprocal of the tangent so the function is calculated as follows:

If the input angle is 0 then the function returns an error because the tangent of 0 is 0 and division by zero is not possible.

Syntax:

Parameters:

number: It is the angle (in radians) whose cotangent value should be calculated.

Return Value:

The COT() function returns the cotangent of the specified angle in radians.

  • It returns a numeric value.
  • It accepts positive and negative angles.
  • It returns NULL if the input is NULL.
  • It returns an error when the input angle is 0 because cotangent of 0 is undefined.

Creating a table

Let us make a table named SignalTowerMeasurements storing information about communication towers and their antenna tilt angles. The table consists of the following fields:

ID: It is a unique identifier for each tower.

TowerName: It is the name of the communication tower.

Location: It is the city where the tower is installed.

TiltAngle: It is the antenna tilt angle measured in radians.

HeightMeters: It is the height of the tower in meters.

SQL Query:

Inserting data

Now we will add some values to the table.

SQL Query:

Retrieving the SignalTowerMeasurements table

Output:

IDTowerNameLocationTiltAngleHeightMeters
1Tower AlphaNew York0.50120
2Tower BetaChicago0.75150
3Tower GammaDallas1.00180
4Tower DeltaMiami1.20140
5Tower EpsilonSeattle0.60160
6Tower ZetaBoston0.90130
7Tower EtaDenver1.10175
8Tower ThetaAtlanta0.40145
9Tower IotaPhoenix0.80155

Examples of COT() Function in SQL

We will utilize the above table in the following examples to comprehend the COT() function in SQL properly.

Example 1: Calculating the Cotangent of Every Antenna Tilt Angle

In this example we will calculate the cotangent of the tilt angle for each communication tower. The COT() function utilizes the values stored in the TiltAngle column and returns their corresponding cotangent values.

SQL Query:

Output:

TowerNameTiltAngleCotangentValue
Tower Alpha0.501.830487721712452
Tower Beta0.751.0734261485493772
Tower Gamma1.000.6420926159343306
Tower Delta1.200.38877956936820496
Tower Epsilon0.601.4616959470781021
Tower Zeta0.900.7935511478423171
Tower Eta1.100.5089681052390643
Tower Theta0.402.3652224200391103
Tower Iota0.800.9712146006504743

Explanation:

The COT() function calculates the cotangent of each tilt angle and returns the output for each row. It performs angle-based calculations directly on table data.

Example 2: Displaying Towers Taller than 150 Meters with their Cotangent Values

In this example we will find cotangent values only of those towers whose height is more than 150 meters.

SQL Query:

Output:

TowerNameHeightMetersTiltAngleCotangentValue
Tower Gamma1801.000.6420926159343306
Tower Epsilon1600.601.4616959470781021
Tower Eta1751.100.5089681052390643
Tower Iota1550.800.9712146006504743

Explanation:

We have utilized the WHERE clause for filtering the towers on the basis of height and the COT() function is applied only to the filtered records.

Example 3: Rounding the Cotangent Values

We are going to round the cotangent values to two decimal places for better readability.

SQL Query:

Output:

TowerNameTiltAngleRoundedCotangent
Tower Alpha0.501.83
Tower Beta0.751.07
Tower Gamma1.000.64
Tower Delta1.200.39
Tower Epsilon0.601.46
Tower Zeta0.900.79
Tower Eta1.100.51
Tower Theta0.402.37
Tower Iota0.800.97

Explanation:

The ROUND() function limits the cotangent values to two decimal places which makes the output cleaner and easier to read.

Example 4: Calculating Cotangent for Towers in Specific Locations

We will here calculate cotangent values for towers located in selected cities.

SQL Query:

Output:

TowerNameLocationTiltAngleCotangentValue
Tower BetaChicago0.751.0734261485493772
Tower EpsilonSeattle0.601.4616959470781021
Tower EtaDenver1.100.5089681052390643

Explanation:

The above SQL query filters towers from specific locations utilizing the WHERE clause and then calculates the cotangent of their tilt angles utilizing the COT() function.

Example 5: Showing All Tower Information with Cotangent

In this example we will show all tower details along with the calculated cotangent value.

SQL Query:

Output:

IDTowerNameLocationHeightMetersTiltAngleCotangentValue
1Tower AlphaNew York1200.501.830487721712452
2Tower BetaChicago1500.751.0734261485493772
3Tower GammaDallas1801.000.6420926159343306
4Tower DeltaMiami1401.200.38877956936820496
5Tower EpsilonSeattle1600.601.4616959470781021
6Tower ZetaBoston1300.900.7935511478423171
7Tower EtaDenver1751.100.5089681052390643
8Tower ThetaAtlanta1450.402.3652224200391103
9Tower IotaPhoenix1550.800.9712146006504743

Explanation:

The above query combines regular table data with the output of the COT() function which permits both stored and calculated values to be viewed together.

Example 6: Calculate the Cotangent of TiltAngle + 0.1

In this example, we will add 0.1 to each tilt angle before calculating the cotangent.

SQL Query:

Output:

TowerNameTiltAngleAdjustedCotangent
Tower Alpha0.501.4616959470781021
Tower Beta0.750.8784777845520119
Tower Gamma1.000.5089681052390643
Tower Delta1.200.27761564654112514
Tower Epsilon0.601.1872418321266793
Tower Zeta0.900.6420926159343306
Tower Eta1.100.38877956936820496
Tower Theta0.401.830487721712452
Tower Iota0.800.7935511478423171

Explanation:

The expression TiltAngle + 0.1 is evaluated first and then the COT() function calculates the cotangent of the updated angle value. It shows that COT() can work with expressions as well as column values.

Example 7: Sort Towers by Cotangent Value

In this example we will sort communication towers based on the cotangent of their antenna tilt angles. It demonstrates how mathematical function results can be used with the ORDER BY clause.

SQL Query:

Output:

TowerNameTiltAngleCotangentValue
Tower Theta0.402.3652224200391103
Tower Alpha0.501.830487721712452
Tower Epsilon0.601.4616959470781021
Tower Beta0.751.0734261485493772
Tower Iota0.800.9712146006504743
Tower Zeta0.900.7935511478423171
Tower Gamma1.000.6420926159343306
Tower Eta1.100.5089681052390643
Tower Delta1.200.38877956936820496

Explanation:

The ORDER BY clause sorts the records according to the cotangent values returned by the COT() function. Towers with higher cotangent values appear first in the result set.

Example 8: Find the Average Cotangent of All Towers

In this example we will calculate the average cotangent value of all antenna tilt angles. It demonstrates how the COT() function can be combined with aggregate functions such as AVG() for data analysis.

SQL Query:

Output:

AverageCotangent
1.1150486973792701

Explanation:

The COT() function first calculates the cotangent of each tilt angle. The AVG() function then computes the average of all cotangent values and returns a single summarized result.

Example 9: Find the Tower with the Highest Cotangent Value

In this example, we will find the communication tower that has the highest cotangent value among all recorded tilt angles.

SQL Query:

Output:

TowerNameTiltAngleCotangentValue
Tower Theta0.402.3652224200391103

Explanation:

The query calculates the cotangent value for every tower and sorts the results in descending order. The LIMIT clause returns only the first record which represents the highest cotangent value.

Difference Between COT() and TAN() Functions

FeatureCOT()TAN()
PurposeIt returns cotangent.It returns tangent.
Formulacos(x) / sin(x) or 1 / TAN(x)sin(x) / cos(x)
InputIt gives angle in radians.It gives angle in radians.
OutputIt is a cotangent value.It is a tangent value.
ExampleCOT(1) = 0.642093TAN(1) = 1.557408

Rules and Behavior of SQL COT() Function

  • The input value must be an angle expressed in radians.
  • COT(π/4) returns 1 because TAN(π/4) = 1.
  • COT(π/2) returns approximately 0 because the tangent approaches infinity.
  • COT(0) is undefined because the tangent of 0 is 0 and division by zero is not possible.
  • Positive angle values return positive cotangent values in most cases.
  • Negative angle values return negative cotangent values in most cases.
  • If the input value is NULL then the function returns NULL.
  • The function returns a numeric value but not an angle.
  • Decimal values are supported and return the cotangent of the specified angle.
  • COT() can be used with columns, constants, variables, expressions and SQL clauses such as SELECT, WHERE and ORDER BY.
  • The function is mathematically equivalent to 1 / TAN(angle).
  • Angles very close to 0 may return extremely large values because the tangent approaches zero.
  • COT(π) returns a very large value because TAN(π) is approximately 0.