標籤:products 資料庫 關鍵字 mysql 產品
select DISTINCT vend_id FROM products; DISTINCT去重複的值,必須放在列名前面
select prod_name from products LIMIT 5; 限制結果 LIMIT
LIMIT 4 OFFSET 3 :從行3開始取4行,== LIMIT 3,4
select acct_key.acct_name from eyou_mail.acct_key; 直接取值資料庫的表內容
select prod_name from products ORDER BY prod_name; ORDER BY 進行排序
select prod_id,prod_price,prod_name from products ORDER BY prod_price,prod_name;
檢索3個列,並按照其中兩個列對結果進行排序------首先按價格,然後按名稱排序
ORDER BY 可以降序(Z到A)順序排序,必須制定關鍵字 DESC。
按照價格以降序排序產品:
select prod_id,prod_price,prod_name From products ORDER BY prod_price DESC;
ORDER BY子句的位置 : 保證它位於FROM子句之後。如果使用LIMIT,它必須位於ORDER BY之後.
select prod_name,prod_price from products where prod_price = 2.50;
select prod_name,prod_price FROM products Where prod_price BETWEEN 5 AND 10;
select prod_name from products where prod_price IS NULL;
OR與AND不同,它只是mysql檢索匹配任意條件的行
Seletc prod_name,prod_price FROM products where vend_id = 1002 OR vend_id = 1003;
select prod_name,prod_price From products WHER (vend_id = 1002 OR vend_id =1003) AND prod_price >= 10;
select prod_name,prod_price from products where vend_id IN (1002,1003) ORDER BY prod_name;
本文出自 “我是小白” 部落格,請務必保留此出處http://878045653.blog.51cto.com/2693110/1529831