← Back to PostgreSQL Course | Chapter 5: Filtering & Functions | Lesson 2 of 7

Math के Functions

Math functions numbers round करते हैं, powers और roots compute करते हैं, और remainders ढूंढते हैं।

In this page:

  1. Math Functions
Syntax
sql
SELECT ROUND(x, n), CEIL(x), FLOOR(x), ABS(x), POWER(x, y), SQRT(x)
FROM table_name;

Math Functions

ROUND(x, n), CEIL, FLOOR, TRUNC, ABS, POWER, SQRT, MOD (या %), SIGN, RANDOM, और LN built in हैं। Integer division truncate होता है, इसलिए decimals पाने के लिए numeric में cast करें। SUM, AVG, MIN, और MAX जैसे aggregates rows के आर-पार काम करते हैं।

ध्यान दें कि site editor में इस्तेमाल होने वाले SQLite version में इनमें से कुछ नहीं हैं, इसलिए ये psql में दिखाए गए हैं।

Note: एक negative second argument वाला ROUND tens, hundreds, वगैरह तक round करता है।

उदाहरण: Math functions

bash
shop=# SELECT ROUND(3.14159, 2) AS r, CEIL(2.1) AS c, FLOOR(2.9) AS f, TRUNC(-2.9) AS t, ABS(-7) AS a;
   r  | c | f |  t | a
------+---+---+----+---
 3.14 | 3 | 2 | -2 | 7
shop=# SELECT POWER(2, 10) AS p, SQRT(144) AS s, MOD(17, 5) AS m, 17 % 5 AS m2;
   p   | s  | m | m2
-------+----+---+----
  1024 | 12 | 2 |  2
shop=# SELECT ROUND(1234.5678, -2) AS to_hundreds, ROUND(2.5) AS r1, ROUND(3.5) AS r2;
 to_hundreds | r1 | r2
-------------+----+----
        1200 |  3 |  4

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह उम्मीद करना कि integer division decimals रखेगा
  2. floats से money round करना
  3. reproducible tests के लिए बिना seed के RANDOM इस्तेमाल करना
चैप्टर सारांश
  • ROUND, CEIL, FLOOR, TRUNC jaise functions मिलते हैं
  • ABS, POWER, SQRT भी उपलब्ध हैं
  • Remainders के लिए MOD या %
  • Decimals के लिए numeric में cast करें
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.