数据库中常用的sql语句有哪些
展开全部
1.检索数据
SELECT prod_nameFROM Products;
#检索单列
SELECT prod_id, prod_name, prod_priceFROMProducts;
#检索多列
SELECT * FROM Products;
#检索所有列
SELECT DISTINCTvend_id FROMProducts;
#检索不同的值
SELECTprod_name FROM Products LIMIT 5;
#返回不超过5行数据
SELECTprod_name FROM Products LIMIT 5 OFFSET 5;
#返回从第5行起的5行数据。LIMIT指定返回的行数,LIMIT带的OFFSET指定从哪儿开始。
2.排序检索数据
SELECTprod_name
FROMProducts
ORDER BYprod_name;
#排序数据
SELECT prod_id, prod_price, prod_name
FROMProducts
ORDER BY prod_price, prod_name;
#按多个列排序
SELECT prod_id, prod_price, prod_name
FROMProducts
ORDER BY 2, 3;
#按列位置排序,第三行表示先按prod_price, 再按prod_name进行排序
SELECT prod_id, prod_price, prod_name
FROMProducts
ORDER BY prod_priceDESC, prod_name;
#prod_price列以降序排序,而prod_name列(在每个价格内)仍然按标准的升序排序
3.过滤数据
SELECT prod_name, prod_price
FROMProducts
WHERE prod_price< 10;
#检查单个值
SELECT prod_name, prod_price
FROMProducts
WHERE vend_id <> ‘DLL01’;
#不匹配检查
SELECT prod_name, prod_price
FROMProducts
WHERE prod_priceBETWEEN 5 AND 10;
#范围值检查
SELECT cust_name
FROMCUSTOMERS
WHERE cust_emailIS NULL;
#空值检查
4.高级数据过滤
SELECTprod_id, prod_price, prod_name
FROMProducts
WHERE vend_id = ‘DLL01’ANDprod_price <= 4;
#AND操作符
SELECTprod_name, prod_price
FROMProducts
WHEREvend_id=’DLL01’ OR vend_id=’BRS01’;
#OR操作符
SELECTprod_name, prod_price
FROMProducts
WHERE (vend_id = ’DLL01’ORvend_id=’BRS01’)
ANDprod_price >= 10;
#求值顺序 AND的优先级高于OR
SELECTprod_name, prod_price
FROMProducts
WHERE vend_idIN (‘DLL01’,’BRS01’)
ORDER BY prod_name;
#IN操作符
SELECT prod_name
FROMProducts
WHERE NOTvend_id = ‘DLL01’
ORDER BY prod_name;
#NOT 操作符
SELECT prod_name
FROMProducts
WHEREvend_id <> ‘DLL01’
ORDER BY prod_name;
#NOT 操作符
SELECT prod_nameFROM Products;
#检索单列
SELECT prod_id, prod_name, prod_priceFROMProducts;
#检索多列
SELECT * FROM Products;
#检索所有列
SELECT DISTINCTvend_id FROMProducts;
#检索不同的值
SELECTprod_name FROM Products LIMIT 5;
#返回不超过5行数据
SELECTprod_name FROM Products LIMIT 5 OFFSET 5;
#返回从第5行起的5行数据。LIMIT指定返回的行数,LIMIT带的OFFSET指定从哪儿开始。
2.排序检索数据
SELECTprod_name
FROMProducts
ORDER BYprod_name;
#排序数据
SELECT prod_id, prod_price, prod_name
FROMProducts
ORDER BY prod_price, prod_name;
#按多个列排序
SELECT prod_id, prod_price, prod_name
FROMProducts
ORDER BY 2, 3;
#按列位置排序,第三行表示先按prod_price, 再按prod_name进行排序
SELECT prod_id, prod_price, prod_name
FROMProducts
ORDER BY prod_priceDESC, prod_name;
#prod_price列以降序排序,而prod_name列(在每个价格内)仍然按标准的升序排序
3.过滤数据
SELECT prod_name, prod_price
FROMProducts
WHERE prod_price< 10;
#检查单个值
SELECT prod_name, prod_price
FROMProducts
WHERE vend_id <> ‘DLL01’;
#不匹配检查
SELECT prod_name, prod_price
FROMProducts
WHERE prod_priceBETWEEN 5 AND 10;
#范围值检查
SELECT cust_name
FROMCUSTOMERS
WHERE cust_emailIS NULL;
#空值检查
4.高级数据过滤
SELECTprod_id, prod_price, prod_name
FROMProducts
WHERE vend_id = ‘DLL01’ANDprod_price <= 4;
#AND操作符
SELECTprod_name, prod_price
FROMProducts
WHEREvend_id=’DLL01’ OR vend_id=’BRS01’;
#OR操作符
SELECTprod_name, prod_price
FROMProducts
WHERE (vend_id = ’DLL01’ORvend_id=’BRS01’)
ANDprod_price >= 10;
#求值顺序 AND的优先级高于OR
SELECTprod_name, prod_price
FROMProducts
WHERE vend_idIN (‘DLL01’,’BRS01’)
ORDER BY prod_name;
#IN操作符
SELECT prod_name
FROMProducts
WHERE NOTvend_id = ‘DLL01’
ORDER BY prod_name;
#NOT 操作符
SELECT prod_name
FROMProducts
WHEREvend_id <> ‘DLL01’
ORDER BY prod_name;
#NOT 操作符
TableDI
2024-07-18 广告
2024-07-18 广告
`VLOOKUP` 匹配出错误的数据通常是由于以下几个原因:1. **查找值错误**:输入的查找值与数据源中的值不匹配,可能是因为拼写错误、大小写不一致或存在不可见的字符。2. **查找区域设置错误**:查找区域的首列必须包含要查找的值,且...
点击进入详情页
本回答由TableDI提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询