这两课主要介绍sql中利用select语句对数据的简单检索。
下面分别讨论不同类型的检索
检索列
单个列
select prod_id
from Products;
多个列
select prod_id, prod_name, prod_price
from Products;
所有列
select *
from Products;
检索不同值 的列
select distinct vend_id
from products;
检索前几列或者后几列
select prod_name
from products
limit 5;
select prod_name
from products
limit 5 offset 5;
检索排序数据
单个列排序
select prod_name
from products
order by prod_name;
多个列排序
select prod_id, prod_price,prod_name
from products
order by prod_price,prod_name;
指定排序的方向
select prod_id, prod_price,prod_name
from products
order by prod_price desc, prod_name;