作者:hypothesis82235 | 来源:互联网 | 2023-09-07 23:30
列转行行转列拉线长按shift双击讲义上有详细步骤,,,,,,,,,,,jndi,,原来添加的不用删除,以后直接添加新代码是吧cv大法,百度,自己代码,ctrlf,
![](https://img.php1.cn/3cd4a/1eebe/cd5/d84f9786330d9e41.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/086aec93f5e1e9b2.webp)
列转行
![](https://img.php1.cn/3cd4a/1e618/cd5/af17da15769ccb2e.jpeg)
行转列![](https://img.php1.cn/3cd4a/1e618/cd5/af17da15769ccb2e.jpeg)
![](https://img.php1.cn/3cd4a/1eebe/cd5/ed19db63ee478b98.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/ff61bfdd3c0af92e.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/e62700fe09f8933e.webp)
![](https://img.php1.cn/3cd4a/1e618/bdf/129913486c37ddf6.jpeg)
![](https://img.php1.cn/3cd4a/1eebe/cd5/72fd2c126203a875.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/d05d9dfd09a56332.webp)
![](https://img.php1.cn/3cd4a/1e618/c5a/d5d40da532c3a782.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/7494af3c1cda418d.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/6789f68dabde0aed.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/086aec93f5e1e9b2.webp)
![](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg)
![](https://img.php1.cn/3cd4a/1eebe/cd5/7d7ef3f69d479716.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/b428d8f746fb8d47.webp)
拉线 长按shift
双击
![](https://img.php1.cn/3cd4a/1eebe/cd5/eec57030b649a106.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/7cccb7e4b6cb5cb8.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/086aec93f5e1e9b2.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/6c257b6ba227cc3e.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/4fae50aeee651818.webp)
![](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg)
![](https://img.php1.cn/3cd4a/1eebe/cd5/0a0ce631ec450943.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/7cccb7e4b6cb5cb8.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/4fae50aeee651818.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/72fd2c126203a875.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/b428d8f746fb8d47.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/b386c433a16f5497.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/2d903861d5ad779c.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/43a754c811e7ec5c.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/b428d8f746fb8d47.webp)
![](https://img.php1.cn/3cd4a/1e618/cd5/af17da15769ccb2e.jpeg)
![](https://img.php1.cn/3cd4a/1eebe/cd5/c72d78d7317a9e8e.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/8ad8f3bf8da691df.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/3e641eb5f5c8cd90.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/4fae50aeee651818.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/60405fda58cd0acd.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/70be2ca197098d98.webp)
![](https://img.php1.cn/3cd4a/9b0d/ae9/2d998ad7838fbf16.jpeg)
![](https://img.php1.cn/3cd4a/1eebe/cd5/8ad8f3bf8da691df.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/b428d8f746fb8d47.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/d34245582687a4e6.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/5287a7b3296ea13e.webp)
![](https://img.php1.cn/3cd4a/1e618/c5a/d5d40da532c3a782.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/d05d9dfd09a56332.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/7494af3c1cda418d.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/b386c433a16f5497.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/dc7ef30f57b727c7.jpeg)
讲义上有详细步骤,,,,,,,,,,,
jndi,,原来添加的不用删除,以后直接添加新代码是吧
cv大法,百度,自己代码,
![](https://img.php1.cn/3cd4a/1e618/c5a/d5d40da532c3a782.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/e3aa5425383ba10d.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/7cccb7e4b6cb5cb8.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/a1be7872e8d4934f.webp)
![](https://img.php1.cn/3cd4a/9b0d/ae9/2d998ad7838fbf16.jpeg)
![](https://img.php1.cn/3cd4a/1eebe/cd5/4283cd4bbba41b87.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/e62700fe09f8933e.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/d05d9dfd09a56332.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/4fae50aeee651818.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/8be1ccb5166feb93.webp)
![](https://img.php1.cn/3cd4a/1e618/cd5/af17da15769ccb2e.jpeg)
![](https://img.php1.cn/3cd4a/18ace/696/1d8e759bd3e6bbec.jpeg)
![](https://img.php1.cn/3cd4a/1eebe/cd5/6789f68dabde0aed.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/5b97d3b808d031e2.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/ed19db63ee478b98.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/011ac27956d007f0.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/70be2ca197098d98.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/5287a7b3296ea13e.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/086aec93f5e1e9b2.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/c72d78d7317a9e8e.webp)
![](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg)
![](https://img.php1.cn/3cd4a/1eebe/cd5/02c379d60086f382.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/6789f68dabde0aed.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/8170a21e8dddfd22.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/011ac27956d007f0.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/780a3060eeed6a4e.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/67cc2e96eddffff8.png)
![](https://img.php1.cn/3cd4a/1eebe/cd5/a5d7215df572c386.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/dc7ef30f57b727c7.jpeg)
![](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg)
![](https://img.php1.cn/3cd4a/1eebe/cd5/bdd1ca32a69bc8b2.webp)
ctrl+f,
官方文档(英文),百度,谷歌,
![](https://img.php1.cn/3cd4a/1eebe/cd5/bcafc120671304eb.webp)
ON 表1.字段 = 表2.字段
ON a.month -1 = b.month
![](https://img.php1.cn/3cd4a/1eebe/cd5/4fae50aeee651818.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/bff2716168d1ed7b.webp)
![](https://img.php1.cn/3cd4a/1eebe/cd5/bff2716168d1ed7b.webp)
前n行,null设置为default,
![](https://img.php1.cn/3cd4a/1eebe/cd5/5b97d3b808d031e2.webp)
use interview;
-- 1.求每个月每个省份的店铺销售额
# (自己做不来,抄的)
SELECT
# 每个月month(order_datetime) AS `month`,
# 每个省份province_name,
# 店铺销售额 OVER(PARTITION BY store_id)SUM(quantity*unit_price) AS `product_sum`
# SUM(quantity*unit_price) OVER(PARTITION BY store_name)AS `store_sum`FROM dim_province p
# 逻辑外键关联
JOIN dim_city c
ON p.province_id = c.province_id
JOIN dim_store s
ON c.city_id=s.city_id
JOIN fact_order_detail f
ON f.store_id = s.store_id
GROUP BY month,province_name
ORDER BY month;-- 2. 每个月的每个产品销售额及其在当月的销售额占比
# (自己做不来,抄的)
SELECT
# 每个月month(order_datetime) AS `month`,
# 每个产品product_name,
# 每个产品销售额SUM( quantity* unit_price) AS `sum_product`,
# 当月的销售额占比sum(quantity* unit_price)/sum(SUM( quantity* unit_price)) OVER () AS `zhanbi`
FROM dim_product d
JOIN fact_order_detail fod
ON d.product_id = fod.product_id
GROUP BY product_name, month
ORDER BY month;-- 3.求每个月的销售额及其环比
WITH a AS(
SELECT
# 每个月month(order_datetime) AS `month`,
# 销售额SUM(quantity* unit_price) AS `Monthly_sales`,
# 本月销售额
# 上一月销售额LAG(SUM(quantity* unit_price)) OVER (ORDER BY month(order_datetime)) AS `last_month_sales`
FROM fact_order_detail
GROUP BY month)
SELECT*,(Monthly_sales-last_month_sales)/last_month_sales AS `sequential`
FROM a;SELECT
# 每个月month(order_datetime) AS `month`,
# 本月销售额SUM(quantity* unit_price) AS `Monthly_sales`,
# 上一月销售额LAG(SUM(quantity* unit_price)) OVER () AS `last_month_sales`,(SUM(quantity* unit_price)-LAG(SUM(quantity* unit_price))OVER ())/LAG(SUM(quantity* unit_price))OVER () AS `环比`
FROM fact_order_detail
GROUP BY month;-- 4.求新增用户量及其留存率
SELECT
# 总共用户量
COUNT(DISTINCT user_id)
# 新增用户量
# LAG(COUNT(user_id))OVER()
# 留存用户量
# 留存率
# COUNT(user_id)OVER(ORDER BY MONTH(order_datetime) ROWS 1 PRECEDING)
FROM fact_order_detail
GROUP BY month(order_datetime);
(1)SELECT
QUANLITY *UNIT_PRICE AS `单个订单销售额`
FROM FACT_ORDER_DETAIL
JOIN DIM_STORE
ON STORE_ID
JOIN DIM_CITY
ON CITY_ID
JOIN DIM_PROVINCE
ON PROVINCE_ID
GROUP BY (F(X...)-ORDER_DATATIME)//30,PRIVICE_NAME
(2)QUANLITY *UNIT_PRICE 订单表,产品表,
单个产品销售额/当月销售额(1题) AS `占比`(3)多个产品*QUANLITY *UNIT_PRICE 每个月 AS`每月销售额`
FROM 产品表,订单表,店铺表
(每月销售额-LAG(每月销售额))/LAG(每月销售额)(4)新增用户 count() 用户表,订单表 上月无 本月有
留存用户 count() 用户表,订单表 上月有 本月有
留存率=留存用户/留存用户-新增用户
笔试题:手写,???
先把表关系清楚
staruml
![](https://img.php1.cn/3cd4a/1eebe/cd5/ddcc574beb16294e.jpeg)
从哪里看这个表一个订单只有一个产品呀
订单基本信息表
订单详细信息表