Recap - Total Gain Shop
CoddyのSQLジャーニー「基礎」セクションの一部。レッスン 40/72。
チャレンジ
簡単利用可能なテーブルとカラム:
<strong>shop</strong>:<strong>price</strong>,<strong>quantity</strong>,<strong>category</strong>,<strong>list_date</strong>
あなたのタスクは、January 1, 2015 から March 18, 2015 の間のショップにおけるアイテムの category ごとの total 収益(売上高)を計算することです。データ入力システムの系統的なエラーにより、データベース内のすべての price の値が一定額だけ本来より低くなっています。
これらの価格を修正するには:
firstに、指定された日付範囲(2015-01-01(2015年1月1日) から2015-03-18(2015年3月18日))内のすべてのアイテムの平均priceを計算します- この平均
priceをeachアイテムのoriginal価格に加算して、correctedな価格を取得します categoryごとに、correctedな価格にquantityを掛け合わせ、それらの値を合計してtotal収益を計算します- 結果を (
category,total_revenue) のペアとして提示し、total_revenueの降順でORDER(ソート) します
自分で試してみよう
-- ステップ2: 再構築した行をグループ化して合計し、大きい順に並べる
SELECT ____
FROM (
-- ステップ1: 各行を再構築し、修正された値が元の値を置き換えるようにする
SELECT ____ AS price, quantity, category, list_date
FROM shop
WHERE list_date BETWEEN '2015-01-01' AND '2015-03-18'
)
GROUP BY ____
ORDER BY ____ DESC基礎のすべてのレッスン
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns自分で練習してみよう: SQLプレイグラウンド