[Day16]汇总函数实作

  1. 在OE帐户的orders_item资料表中,找出单价最高的产品。
SELECT MAX(unit_price)FROM order_items;

https://ithelp.ithome.com.tw/upload/images/20211001/201409158V4DLfYktx.png

  1. 在HR帐户的employees资料表中,查询各部门员工的平均薪水(显示至小数一位数,其余四舍五入)。输出结果依序显示部门代码和平均薪水,并降幂排序部门平均薪水。
SELECT department_id"部门代号", ROUND(AVG(salary),1)"平均薪水"
FROM employees
GROUP BY department_id
ORDER BY AVG(salary) DESC;

https://ithelp.ithome.com.tw/upload/images/20211001/201409156OJeKDxHkc.png

  1. 在OE的orders_items资料表中,查询每张订单中的最高订购金额。
SELECT order_id, MAX(unit_price*quantity)"最高订购金额"
FROM order_items
GROUP BY order_id;

https://ithelp.ithome.com.tw/upload/images/20211001/20140915SRUv7QnQ6c.png

  1. 在HR中的employees和department资料表中,将部门代号30以後的资料依照代码排序,并显示每一个部门每个职员每个月的薪水总额。
SELECT department_id, job_id, SUM(salary)
FROM employees
WHERE department_id>30
GROUP BY department_id, job_id
ORDER BY department_id;

https://ithelp.ithome.com.tw/upload/images/20211001/20140915xnmd4WQVLj.png

  1. 在OE中的product_information和inventroies资料表中,查询product_information表中,product_status为可被订购的quantity_on_hand(是的一个栏位)。
    说明:
    1.product_information:product_id, product_information
    inventories:product_id, quantity_on_hand
    2.因为产品可被订购的在手量是在inventroies里,所以和product_information资料表合并时,需使用左外部合并。
    3.在SELECT子句内,汇总函数以外的栏位就是分组栏位,所以最後面加上:GROUP BY pi.product_id, pi.product_status。
SELECT pi.product_id, pi.product_status, sum(i.quantity_on_hand)"在手量"
FROM product_information pi
LEFT OUTER JOIN inventories i
ON (pi.product_id=i.product_id)
WHERE(pi.product_status='orderable')
GROUP BY pi.product_id, pi.product_status;

https://ithelp.ithome.com.tw/upload/images/20211001/20140915zalmJRrMMn.png


<<:  D16 - 那个圆圆的东西 - 物件原型 & 原型链

>>:  [Day16] TS:在 Mapped Type 中修改物件的 property modifiers:理解 Partial、Required 和 Readonly 的实作

Day5 「开机」学习 Lua - 变数型别与宣告

上一回,我有了好的 Lua 开发工具,可以研究 CC: Tweaked 的程序码 今天,我重新以 C...

Day14 - 做一半的产品编辑 modal

今天回顾六角的课程范例,重做一遍产品编辑 modal ,但目前只做了一半 <template&...

Day 08 - Kbars

本篇重点 Kbars 介绍及属性说明 使用 Pandas 将 Kbars 资料转换为 DataFra...

信件样式与内容编辑

Markdown 先看看目前刚新建好的 Markdown 信件。 @component('mail:...

NNI大纲描述

基本名词及观念: • Experiment:一次实验,如寻找最好的神经网路架构。经多个autoML ...