W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
表達式是計算值的一個或多個值、運算符和SQL函數(shù)的組合。這些SQL表達式類似于公式,它們是用查詢語言編寫的。
您還可以使用它們查詢數(shù)據(jù)庫中的特定數(shù)據(jù)集。
考慮SELECT語句的基本語法,如下所示:
SELECT column1, column2, columnN
FROM table_name
WHERE [CONDITION|EXPRESSION];
有不同類型的sql表達式,如下所示:
現(xiàn)在讓我們詳細(xì)討論每一個問題。
SQL布爾表達式基于匹配單個值獲取數(shù)據(jù)。
句法:
SELECT column1, column2, columnN
FROM table_name
WHERE SINGLE VALUE MATCHING EXPRESSION;
使用具有以下記錄的Customers表:
SQL> SELECT * FROM CUSTOMERS;
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
7 rows in set (0.00 sec)
下表是一個簡單的示例,展示了各種sql布爾表達式的用法。
SQL> SELECT * FROM CUSTOMERS WHERE SALARY = 10000;
+----+-------+-----+---------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+-------+-----+---------+----------+
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+-------+-----+---------+----------+
1 row in set (0.00 sec)
數(shù)值表達式用于在任何查詢中執(zhí)行任何數(shù)學(xué)運算。
句法:
SELECT numerical_expression as OPERATION_NAME
[FROM table_name
WHERE CONDITION] ;
這里,數(shù)值表達式用于數(shù)學(xué)表達式或任何公式。下面是一個簡單的示例,展示了SQLNDigitic表達式的用法:
SQL> SELECT (15 + 6) AS ADDITION
+----------+
| ADDITION |
+----------+
| 21 |
+----------+
1 row in set (0.00 sec)
有幾個內(nèi)置函數(shù),如avg()、sum()、count()等,用于對表或特定表列執(zhí)行所謂的聚合數(shù)據(jù)計算。
SQL> SELECT COUNT(*) AS "RECORDS" FROM CUSTOMERS;
+---------+
| RECORDS |
+---------+
| 7 |
+---------+
1 row in set (0.00 sec)
日期表達式返回當(dāng)前系統(tǒng)日期和時間值:
SQL> SELECT CURRENT_TIMESTAMP;
+---------------------+
| Current_Timestamp |
+---------------------+
| 2009-11-12 06:40:23 |
+---------------------+
1 row in set (0.00 sec)
另一個日期表達式如下所示:
SQL> SELECT GETDATE();;
+-------------------------+
| GETDATE |
+-------------------------+
| 2009-10-22 12:07:18.140 |
+-------------------------+
1 row in set (0.00 sec)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: