当前位置:网站首页>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 :
边栏推荐
- sprintf 格式代码使用不规范在不同平台下的表现
- Wechat applet: an artifact for calculating the full amount of orders
- When I was young, I thought my father was omnipotent
- About information disclosure and defense
- FS4059A与FS5080E充电芯片的区别
- Go grouping & sorting
- Implementation of MySQL custom sequence number
- 啊哈C语言 第7章 有了它你能做更多的事(第27-28讲)
- Meteorological mapping software panoply tutorial (updated from time to time)
- Complete one-time GC process of JVM principle
猜你喜欢

Spark 离线开发框架设计与实现

Win11不能录制音频怎么办?Win11无法录入声音的解决方法

Export PDF with watermark

电脑开机显示器黑屏是什么原因,电脑显示器黑屏怎么办

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

MCS:连续随机变量——LogNormal分布

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

Wechat applet: Star Trek spaceship ticket production and generation

AI艺术的基因工程?使用 #Artbreeder 改变图像的任意形态

Markdown add background color to the picture
随机推荐
Stm32cube serial port uses dma+idle to receive variable length data
Mobile power fast charging qc3.0 scheme chip ip5318 fast charging scheme
Introduction to MySQL (II) sub query + Association
Yingjixin launched 4 series of lithium batteries 100W mobile power supply voltage rise and fall scheme SOC chip ip5389
WebRTC[47] - WebRTC 保存 YUV 数据的常用方式
QT QWidget nesting relative position acquisition (QT drawing nesting)
LeetCode-1757. Recyclable and low-fat products_ SQL
Win11如何开启移动热点?Win11开启移动热点的方法
Design and implementation of spark offline development framework
Lottery DDD code
英集芯ip6806无线充电方案5W过Qi认证外围精简14颗器件
Composite API
Is there a real part-time job online? How do college students find part-time jobs in summer?
About dos/ddos attack and defense
Wechat applet: elderly blessing short video
STC 32比特8051單片機開發實例教程 一 開發環境搭建
Software project management 8.4 Software project quality plan
Jenkins安装部署以及自动构建和发布jar应用
ArcTime 制作中英文字幕视频
markdown给图片加背景色