--检索单列数据
select prod_name from Products;
--检索多列数据
select prod_name,prod_price,prod_id from Products
--检索所有列
select * from Products
--DISTINCT关键字
select distinct vend_id from Products
--限制结果
select top 5 prod_name from Products
--排序数据
select prod_name from Products order by prod_name
--按多个排序
select prod_name,prod_price,prod_id from Products order by prod_price,prod_name;
--指定排序方向
select prod_id,prod_price,prod_name from Products order by prod_price asc
--过滤数据
select prod_name,prod_price from Products where prod_price=3.49;
select prod_name,prod_price from Products where prod_price<10;
select vend_id,prod_name from Products where vend_id <> 'DLL01';
select prod_name,prod_price from Products where prod_price between 5 and 10;
select prod_name from Products where prod_price is null;
select prod_id,prod_price,prod_name from Products where vend_id='DLL01'and prod_price<=4;
select prod_name,prod_price from Products where vend_id in('DLL01','BRS01')order by prod_name;
select prod_name,vend_id from Products where not vend_id='DLL01'order by prod_name
--通配符
select prod_id,prod_name from Products where prod_name like '%bean bag%'
select prod_id,prod_name from Products where prod_name like '_ inch teddy bear';
select cust_contact from Customers where cust_contact like '[JM]%'
--拼接字段
select vend_name+'('+vend_country+')' from Vendors order by vend_name;
select RTRIM(vend_name)+'('+RTRIM(vend_country)+')'as vend_title from Vendors order by vend_name;
select prod_id,quantity,item_price,quantity*item_price as expanded_price from OrderItems where order_num=20008;
select prod_name from Products;
--检索多列数据
select prod_name,prod_price,prod_id from Products
--检索所有列
select * from Products
--DISTINCT关键字
select distinct vend_id from Products
--限制结果
select top 5 prod_name from Products
--排序数据
select prod_name from Products order by prod_name
--按多个排序
select prod_name,prod_price,prod_id from Products order by prod_price,prod_name;
--指定排序方向
select prod_id,prod_price,prod_name from Products order by prod_price asc
--过滤数据
select prod_name,prod_price from Products where prod_price=3.49;
select prod_name,prod_price from Products where prod_price<10;
select vend_id,prod_name from Products where vend_id <> 'DLL01';
select prod_name,prod_price from Products where prod_price between 5 and 10;
select prod_name from Products where prod_price is null;
select prod_id,prod_price,prod_name from Products where vend_id='DLL01'and prod_price<=4;
select prod_name,prod_price from Products where vend_id in('DLL01','BRS01')order by prod_name;
select prod_name,vend_id from Products where not vend_id='DLL01'order by prod_name
--通配符
select prod_id,prod_name from Products where prod_name like '%bean bag%'
select prod_id,prod_name from Products where prod_name like '_ inch teddy bear';
select cust_contact from Customers where cust_contact like '[JM]%'
--拼接字段
select vend_name+'('+vend_country+')' from Vendors order by vend_name;
select RTRIM(vend_name)+'('+RTRIM(vend_country)+')'as vend_title from Vendors order by vend_name;
select prod_id,quantity,item_price,quantity*item_price as expanded_price from OrderItems where order_num=20008;