W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
表達(dá)式是計(jì)算值的一個(gè)或多個(gè)值、運(yùn)算符和SQL函數(shù)的組合。這些SQL表達(dá)式類(lèi)似于公式,它們是用查詢(xún)語(yǔ)言編寫(xiě)的。
您還可以使用它們查詢(xún)數(shù)據(jù)庫(kù)中的特定數(shù)據(jù)集。
考慮SELECT語(yǔ)句的基本語(yǔ)法,如下所示:
SELECT column1, column2, columnN
FROM table_name
WHERE [CONDITION|EXPRESSION];
有不同類(lèi)型的sql表達(dá)式,如下所示:
現(xiàn)在讓我們?cè)敿?xì)討論每一個(gè)問(wèn)題。
SQL布爾表達(dá)式基于匹配單個(gè)值獲取數(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)
下表是一個(gè)簡(jiǎn)單的示例,展示了各種sql布爾表達(dá)式的用法。
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ù)值表達(dá)式用于在任何查詢(xún)中執(zhí)行任何數(shù)學(xué)運(yùn)算。
句法:
SELECT numerical_expression as OPERATION_NAME
[FROM table_name
WHERE CONDITION] ;
這里,數(shù)值表達(dá)式用于數(shù)學(xué)表達(dá)式或任何公式。下面是一個(gè)簡(jiǎn)單的示例,展示了SQLNDigitic表達(dá)式的用法:
SQL> SELECT (15 + 6) AS ADDITION
+----------+
| ADDITION |
+----------+
| 21 |
+----------+
1 row in set (0.00 sec)
有幾個(gè)內(nèi)置函數(shù),如avg()、sum()、count()等,用于對(duì)表或特定表列執(zhí)行所謂的聚合數(shù)據(jù)計(jì)算。
SQL> SELECT COUNT(*) AS "RECORDS" FROM CUSTOMERS;
+---------+
| RECORDS |
+---------+
| 7 |
+---------+
1 row in set (0.00 sec)
日期表達(dá)式返回當(dāng)前系統(tǒng)日期和時(shí)間值:
SQL> SELECT CURRENT_TIMESTAMP;
+---------------------+
| Current_Timestamp |
+---------------------+
| 2009-11-12 06:40:23 |
+---------------------+
1 row in set (0.00 sec)
另一個(gè)日期表達(dá)式如下所示:
SQL> SELECT GETDATE();;
+-------------------------+
| GETDATE |
+-------------------------+
| 2009-10-22 12:07:18.140 |
+-------------------------+
1 row in set (0.00 sec)
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話(huà):173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: