1. 编写 SQL 语句,从 Vendors 表中检索供应商名称(vend_name),仅返 回加利福尼亚州的供应商(这需要按国家[USA]和州[CA]进行过滤, 没准其他国家也存在一个加利福尼亚州)。提示:过滤器需要匹配字符串。
select vend_name from Vendors where vend_country='[USA]' and vend_state='[CA]';
2. 编写 SQL 语句,查找所有至少订购了总量 100 个的 BR01、BR02 或 BR03 的订单。你需要返回 OrderItems 表的订单号(order_num)、 产品 ID(prod_id)和数量,并按产品 ID 和数量进行过滤。提示: 根据编写过滤器的方式,可能需要特别注意求值顺序。
select order_num,prod_id,number from OrderItems where number>='100' and prod_id in('BR01','BR02','BR03');
3. 现在,我们回顾上一课的挑战题。编写 SQL 语句,返回所有价格在 3 美元到 6美元之间的产品的名称(prod_name)和价格(prod_price)。 使用 AND,然后按价格对结果进行排序。
select prod_name,prod_price from Products where prod_price>='3美元’ and prod_price <='6美元‘;
select prod_name,prod_price from Products where prod_price between 3 and 6;
4. 下面的 SQL 语句有问题吗?(尝试在不运行的情况下指出。)
select vend_name from vendors where vend_country='USA' and vend_state='CA' order by vend_name;