当前位置:网站首页>Real MySQL interview question (30) -- shell real estate order analysis
Real MySQL interview question (30) -- shell real estate order analysis
2022-06-23 05:40:00 【Socialphobia_ FOGO】
Real estate order analysis
“ Transaction order form ” It records a real estate platform ( It's like chain home 、 Shells, etc ) Details of daily house transactions .( Shell interview questions )
Field “ Transaction source channel ” The value in is “ Source character ”、“ The owner entrusts online ”、“null” Indicates offline channels , The rest of the transaction source channels are online .
requirement :
1. As of yesterday, the volume of second-hand online transaction orders accounted for ( Including parking space )>=50% Your store can win awards ;
( Proportion of online transactions = Online order volume / Total number of orders )
2. The number of stores that meet the award-winning conditions 1 If you trade on a single line, you can get 200 garena ( Can be used to exchange for bonuses ), The first 2 Single can get 400 garena , The first 3 Single and above can obtain 800 garena , But the garage doesn't reward ( Field “ The purpose of the house is ” The value in is ” Parking lot ”、” The garage ” Think it's a garage );
3. In a continuous SQL Realize the above requirements in , Cannot be split into multiple SQL, The table fields that must be output are as follows ( Can increase the );
WITH t1 AS(-- Find out whether it is online
SELECT *,
CASE WHEN Transaction source channel IN(' Source character ',' The owner entrusts online ') OR Transaction source channel IS NULL THEN ' no ' ELSE ' yes ' END AS Online or not
FROM Transaction order form
),
t2 AS (-- Calculate the online transaction proportion of each store
SELECT Contracted broker stores ,SUM(CASE WHEN Online or not =' yes ' THEN 1 ELSE 0 END)/COUNT(*) AS The proportion of online transactions in the store where the broker is located
FROM t1
GROUP BY Contracted broker stores
),
t3 AS (-- Get the original table plus the previous request 2 A field , And add an online order sort
SELECT t1.*,t2. The proportion of online transactions in the store where the broker is located ,
row_number()over(PARTITION BY Contracted broker stores ORDER BY Signing time ) AS Order sequence
FROM t1
JOIN t2
ON t1. Contracted broker stores =t2. Contracted broker stores
WHERE Online or not =' yes '
AND The proportion of online transactions in the store where the broker is located >=0.5
AND The purpose of the house is IS NULL
),
t4 AS (-- Match all the orders for shell coins
SELECT *,
CASE WHEN Order sequence =1 THEN '200'
WHEN Order sequence =2 THEN '400'
WHEN Order sequence >=3 THEN '800'
ELSE 0 END AS Shell currency shall be issued for this order
FROM t3
)
SELECT t1.*,t2. The proportion of online transactions in the store where the broker is located ,IFNULL(t4. Shell currency shall be issued for this order ,0) AS Shell currency shall be issued for this order
FROM t1
LEFT JOIN t2
ON t1. Contracted broker stores =t2. Contracted broker stores
LEFT JOIN t4
ON t1. agreement id=t4. agreement id
ORDER BY Contracted broker stores , Signing time
give the result as follows :
边栏推荐
- Go grouping & sorting
- GO语言-panic和recover
- After the idea code is developed, the code is submitted. If the branch is found to be incorrect after submission, how can I withdraw it
- sprintf 格式代码使用不规范在不同平台下的表现
- 51万奖池邀你参战——第二届阿里云ECS CloudBuild开发者大赛来袭
- How much disk IO will actually occur for a byte of the read file?
- Pkav simple blasting
- Current situation and development of containerization technology under the cloud native trend
- 低成本5W无线充电器方案FS68001B简便充电芯片
- MCS: continuous random variable - student's t distribution
猜你喜欢

After the idea code is developed, the code is submitted. If the branch is found to be incorrect after submission, how can I withdraw it

STC 32比特8051單片機開發實例教程 一 開發環境搭建

MySQL面试真题(二十四)——行列互换

云原生数据库是未来数据库的天下

Win11应用商店一直转圈解决办法

Markdown add background color to the picture

read 文件一个字节实际会发生多大的磁盘IO?

Leetcode 797: all possible paths

How to move the software downloaded from win11 app store to the desktop

C primer plus学习笔记 —— 2、常量与格式化IO(输入/输出)
随机推荐
visdom的使用
Management system of borrowed books based on SSM framework
Heimdall Database Proxy横向扩展提高20倍
啊哈C语言 第7章 有了它你能做更多的事(第27-28讲)
Wechat applet: unfashionable love talk
Markdown add background color to the picture
Win11不能录制音频怎么办?Win11无法录入声音的解决方法
MCS: continuous random variable - student's t distribution
Array The from method creates an undefined array of length n
H5 适配全面屏
Build a gocd environment
电脑开机显示器黑屏是什么原因,电脑显示器黑屏怎么办
Win软件 - (Net-Framework)已处理证书链,但是在不受信任提供程序信任的根证书中终止
SIFT feature point extraction
What if win11 cannot record audio? Solution of win11 unable to input sound
Win11应用商店一直转圈解决办法
About information disclosure and defense
Konva series tutorial 1:what is konva?
What is the reason for the black screen of the computer monitor when the computer is turned on? What should I do about the black screen of the computer monitor
Ip6809 three coil 15W wireless charging transmitter scheme IC British chip