當前位置:網站首頁>第2章 基礎查詢與排序

第2章 基礎查詢與排序

2022-07-23 14:28:39長沙的沙

Q2.1

SELECT product_name, regist_date
  FROM product
 WHERE regist_date >'2009-04-28';

Q2.2

product_id|product_name|product_type|sale_price|purchase_price|regist_date|
----------+------------+------------+----------+--------------+-----------+

Q2.3

SELECT product_name, sale_price, purchase_price
  FROM product
 WHERE sale_price - purchase_price>=500;
 
SELECT product_name, sale_price, purchase_price
  FROM product
 WHERE  purchase_price-sale_price <=-500;

Q2.4

SELECT product_name,product_type, sale_price*0.9-purchase_price   As "profit"
  FROM product
 WHERE  sale_price*0.9-purchase_price >100;

Q2.5

出現的錯誤有:

  1. sum函數只能用數值型的列作為參數
  2. 在聚合函數的SELECT子句中寫了聚合鍵以外的列使用COUNT等聚合函數時,SELECT子句中如果出現列名,只能是GROUP BY子句中指定的列名(也就是聚合鍵)。
  3. WHERE 子句寫在了 GROUP BY 子句之後

Q2.6

SELECT product_type,SUM(sale_price), SUM(purchase_price) 
 FROM product
GROUP BY product_type
HAVING SUM(sale_price)>1.5*SUM(purchase_price) ;

Q2.7

select * from product 
order by - regist_date;

版權聲明
本文為[長沙的沙]所創,轉載請帶上原文鏈接,感謝
https://cht.chowdera.com/2022/204/202207230835452372.html

隨機推薦