回顾之前学习数据库的相关操作,复习时顺便记录下,以便以后自己可以再次查看!!!
/*
排序检索数据
*/
(1)select prod_name
from products
order by prod_name;//ORDER BY使prod_name列以字母顺序排序数据
(2)select prod_id,prod_price,prod_name
from products
order by prod_price,prod_name;//其中两个列对结果进行排序——首先按 价格,然后再按名称排序。
(3)select prod_id, prod_price, prod_name
from products
order by prod_price DESC;//按价格以降序排序产品
(4)select prod_id, prod_price, prod_name
from products
order by prod_price desc,prod_name;//以降序排序产品 (最贵的在最前面),然后再对产品名排序
(5)select prod_price
from products
order by prod_price desc
limit 1;//prod_price DESC保证行是按照由最昂贵到最便宜检索的,而 LIMIT 1告诉MySQL仅返回一行。 而这一行就是最高值
/*
过滤数据
*/
(6)select prod_name,prod_price
from products
where prod_price = 2.50;//返回,当prod_price = 2.50时,prid_name和prod_price这两个列的值
(7)select prod_name, prod_price
from products
where prod_name = 'fuses';//检查WHERE prod_name=‘fuses’语句,它返回prod_name的值 为Fuses的一行。
(8)select prod_name, prod_price
from products
where prod_price < 10;//列出价格小于10美元的所有产品的名称和价格
(9)select prod_name, prod_price
from products
where prod_price <= 10;//列出价格小于等于10美元的所有产品的名称和价格(相对于前面的例子多出了两项)
(10)select vend_id, prod_name
from products
where vend_id <> 1003;//列出不是由供应商1003制造的所有产品
(11)select vend_id, prod_name
from products
where vend_id != 1003;//列出不是由供应商1003制造的所有产品
(12)select prod_name, prod_price
from products
where prod_price between 5 and 10;//列出价格在5和10之间的所有产品的名称和价格
(13)select prod_name
from products
where prod_price is null;//返回没有价格(空prod_price字段,不是价格为0)的所有 产品,由于表中没有这样的行,所以没有返回数据
(14)select cust_id
from customers
where cust_email is null;//返回没有填写电子邮件的顾客ID
/*
数据过滤
*/
(15)select prod_id, prod_price, prod_name
from products
where vend_id = 1003 and prod_price <= 10;//返回由供应商1003制造且价格小于等于10美元的所 有产品的名称和价格
(16)select prod_name, prod_price
from products
where vend_id = 1002 or vend_id = 1003;//返回由供应商1002或者供应商1003制造的所有产品的价格和名称
(17)select prod_name, prod_price
from products
where vend_id = 1002 or vend_id = 1003 and prod_price >= 10;//返回由供应商1002或者供应商1003制造的而且价格大于等于的10所有产品的价格和名称
(18)select prod_name, prod_price
from products
where (vend_id = 1002 or vend_id = 1003) and prod_price >= 10;//返回由供应商1002和1003所制作的所有产品且价格大于等于10的价格和名称
(19)select prod_name, prod_price
from products
where vend_id in (1002,1003)
order by prod_name;//返回由制造商1002和1003制造的产品并且按照产品名称排序
(21)select prod_name, prod_price
from products
where vend_id = 1002 or vend_id = 1003
order by prod_name;//返回由制造商1002和1003制造的产品并且按照产品名称排序
(22)select prod_name, prod_price
from products
where vend_id not in (1002,1003)
order by prod_name;//列出除1002和1003之外的所有供应商制造的产品并且按照产品的名称排序
数据库实际查询操作回顾(一)
数据库实际查询操作回顾(三)
数据库实际查询操作回顾(四)
数据库实际查询操作回顾(五)
数据库实际查询操作回顾(六)
数据库实际查询操作回顾(七)
数据库实际查询操作回顾(八)
数据库实际查询操作之相关数据库代码(MySQL必知必会数据库代码)