前言:但行好事,莫问前程
检索数据
1 2
| SELECT products.prod_name FROM crashcourse.products;
|
对检索的数据进行排序
1 2 3
| SELECT prod_name FROM products ORDER BY prod_name;
|
1 2 3
| SELECT prod_id,prod_price,prod_name FROM products ORDER BY prod_price,prod_name;
|
1 2 3
| SELECT prod_id,prod_price,prod_name FROM products ORDER BY prod_price DESC,prod_name;
|
过滤数据
1 2 3
| SELECT prod_name FROM products WHERE pro_price IS NULL;
|
高级过滤数据
1 2 3
| SELECT prod_name,prod_price FROM products WHERE (vend_id=1002 OR vend_id=1003) AND prod_price>=10;
|
1 2 3 4
| SELECT prod_name,prod_price FROM products WHERE vend_id NOT IN (1002,1003) ORDER BY prod_name;
|
使用通配符过滤
1 2 3
| SELECT prod_id,prod_name FROM products WHERE prod_name LIKE '_Jet%';
|
使用正则表达式执行搜索
1 2 3 4
| SELECT prod_name; FROM products WHERE REGEXP_LIKE(prod_name,'^\(\d{4,5} sticks?\)$');
|