1、
CREATE TABLE drink_info(drink_name VARCHAR(30),cost DEC(8,2),carbs DEC(8,2),color VARCHAR(20),ice CHAR(1),calories INT);
2、对char varchar进行运算符比较运算,比较运算符会按字母顺序地评估所有事物的大小。
假设你要选出所有名称以“L”开头的饮料,查询语句如下:
SELECT drink_name FROM drink_info WHERE drink_name >= ‘L‘ AND drink_name < ‘M‘;
3、不可以直接选择NULL,但可以利用关键字选择NULL
SELECT drink_name FROM drink_info WHERE calories IS NULL;
4、LIKE 喜欢和通配符在一起,第一通配符是%,它是任意数量的未知字符的替身
SELECT first_name FROM my_contacts WHERE first_name LIKE ‘%im‘;
LIKE喜欢的第二个通配符是下划线 _ ,它是一个未知字符的替身。
SELECT first_name FROM my_contacts WHERE first_name LIKE ‘_im‘;
5、BETWEEN 查询某一范围内的语句,范围的起止值也会包含在查找范围内。
SELECT drink_name FROM drink_info WHERE calories BETWEEN 30 AND 60;
6、IN NOT IN 注意NOT 要放在WHERE AND OR 的后面,NOT IN 中的NOT除外;
SELECT drink_name FROM easy_drinks WHERE main = IN (‘peach nectar‘,‘soda‘);
SELECT drink_name FROM easy_info WHERE NOT carbs BETEWEEN 3 AND 5;
SELECT date_name FROM black_book WHERE NOT date_name LIKE ‘A%‘
AND NOT date_name LIKE ‘B%‘;
原文地址:http://10226243.blog.51cto.com/10216243/1672911