美文网首页
《SQL必知必会》(第5版)

《SQL必知必会》(第5版)

作者: 布衣夜行人 | 来源:发表于2022-07-17 16:31 被阅读0次

第2课-检索数据

2.9 挑战题

1、编写SQL语句,从Customers表中检索所有的ID(cust_id)

SELECT cust_id from Customers

正确答案:

SELECT cust_id
FROM Customers;

2、

SELECT DISTINCT prod_id from OrderItems

正确答案:

SELECT DISTINCT prod_id
FROM OrderItems;

3、

#SELECT * from Customers
SELECT cust_id from Customers

正确答案:

SELECT *
# SELECT cust_id 
FROM Customers;

第3课-排序检索数据

1、

SELECT cust_name from Customers ORDER BY cust_name DESC;

正确答案:

SELECT cust_name
FROM Customers
ORDER BY cust_name DESC;

2、

SELECT cust_id, order_num FROM Orders
ORDER BY cust_id, order_num DESC;(这里应该是按订单日期来进行排序)

正确答案:

SELECT cust_id, order_num
FROM Orders
ORDER BY cust_id, order_date DESC;

3、

SELECT number,item_price FROM OrderItems
ORDER BY number DESC,item_price DESC;

正确答案:

SELECT quantity, item_price
FROM OrderItems
ORDER BY quantity DESC, item_price DESC;

4、题目四回答正确

第4课-过滤数据

1、

SELECT prod_id, prod_name FROM Products
WHERE prod_price=9.49;

正确答案:

SELECT prod_id, prod_name
FROM Products
WHERE prod_price = 9.49;

2、

SELECT prod_id, prod_name FROM Products
WHERE prod_price >=9.49;

正确答案:

SELECT prod_id, prod_name
FROM Products
WHERE prod_price >= 9;

3、

SELECT DISTINCT order_num FROM OrderItems
WHERE number >=100;

正确答案:

SELECT DISTINCT order_num
FROM OrderItems
WHERE quantity >=100;

4、

SELECT prod_name, prod_price FROM Products
WHERE prod_price BETWEEN 3 AND 6
ORDER BY prod_price DESC;

正确答案:

SELECT prod_name, prod_price
FROM products
WHERE prod_price BETWEEN 3 AND 6
ORDER BY prod_price;

第5课-高级数据过滤

1、

SELECT vend_name FROM Vendors
WHERE country="USA" AND state="CA";

正确答案:

SELECT vend_name
FROM Vendors
WHERE vend_country = 'USA' AND vend_state = 'CA';

2、

SELECT order_num, prod_id, number FROM OrderItems
WHERE number >=100 AND prod_id IN ('BR01','BR02','BR03')

正确答案:

-- Solution 1
SELECT order_num, prod_id, quantity
FROM OrderItems
WHERE (prod_id='BR01' OR prod_id='BR02' OR prod_id='BR03')
 AND quantity >=100;

-- Solution 2
SELECT order_num, prod_id, quantity
FROM OrderItems
WHERE prod_id IN ('BR01','BR02','BR03')
 AND quantity >=100;

第6课-用通配符进行过滤

1、

SELECT prod_name, prod_desc FROM Products
WHERE prod_desc Like '%toy%';

正确答案:

SELECT prod_name, prod_desc
FROM Products
WHERE prod_desc LIKE '%toy%';

2、

SELECT prod_name, prod_desc FROM Products
WHERE NOT prod_desc Like '%toy%'
ORDER BY prod_name;

正确答案:

SELECT prod_name, prod_desc
FROM Products
WHERE NOT prod_desc LIKE '%toy%'
ORDER BY prod_name;

3、

SELECT prod_name, prod_desc FROM Products
(WHERE prod_desc Like '%toy%')
AND
(WHERE prod_desc Like '%carrots%');

正确答案:

SELECT prod_name, prod_desc
FROM Products
WHERE prod_desc LIKE '%toy%' AND prod_desc LIKE '%carrots%';

4、

SELECT prod_name, prod_desc FROM Products
WHERE prod_desc Like '%toy%carrots%';

正确答案:

SELECT prod_name, prod_desc
FROM Products
WHERE prod_desc LIKE '%toy%carrots%';

相关文章

  • SQL必知必会

    《SQL必知必会》SQL是使用 广泛的数据库语言,几乎所有重要的DBMS都支持SQL。《SQL必知必会(第4版)》...

  • 《SQL必知必会 第4版》PDF高清完整版-免费下载

    《SQL必知必会 第4版》PDF高清完整版-免费下载 《SQL必知必会 第4版》PDF高清完整版-免费下载 下载地...

  • SQL必知必会

    SQL 必知必会 第1章 了解SQL 定义 结构化查询语言(Structured Query Language) ...

  • 第三周学习计划

    本周将继续学习SQL必知必会这本书,从第8课开始。

  • SQL必知必会

    一、SQL是Structured Query Language结构化数据语言。 是一种专门用来与数据库沟通的语言基...

  • Sql必知必会

    mac MySQL 下载最新的MySQL社区版[https://dev.mysql.com/downloads/m...

  • SQL必知必会

    一、了解SQL 1、数据库:保存有组织的数据的容器,≠数据库软件 数据库软件:数据库管理系统(DBMS) 2、表:...

  • SQL必知必会

    oracle只显示前几行 select prod_name from products where rownum ...

  • SQL必知必会

    检索数据 搜索并去重【DISTINCT】: 限制结果【LIMIT】: LIMIT指定返回的行数: OFFSET指定...

  • 书籍归档

    PHP入门到精通(朋友赠送) 正则表达式必知必会(朋友赠送) SQL必知必会(朋友赠送) Docker技术入门与实...

网友评论

      本文标题:《SQL必知必会》(第5版)

      本文链接:https://www.haomeiwen.com/subject/mgewbrtx.html