Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[Leet code] 1173. Immediate Food Delivery I

์ธ” 2023. 8. 3. 11:41

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์— ํ™œ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ ์ž๋ฃŒ ์ถœ์ฒ˜๋Š”

       ๋ฆฌํŠธ์ฝ”๋“œ Problems, https://leetcode.com/problemset/all/์ž„์„ ๋ฐํž™๋‹ˆ๋‹ค.


โœ”๋ฌธ์ œ

https://leetcode.com/problems/immediate-food-delivery-i/description/

 

Immediate Food Delivery I - LeetCode

Can you solve this real interview question? Immediate Food Delivery I - Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

Table : Delivery

If the customer's preferred delivery date is the same as the order date, then the order is called immediate; otherwise, it is called scheduled.

Find the percentage of immediate orders in the table, rounded to 2 decimal places.

The result format is in the following example.


โœ” ํ’€์ด

  ๋ฌธ์ œ ์š”๊ตฌ์‚ฌํ•ญ  

๊ณ ๊ฐ์ด ์„ ํ˜ธํ•˜๋Š” ๋ฐฐ์†ก์ผ์ž๊ฐ€ ์ฃผ๋ฌธ์ผ์ž์™€ ๋™์ผํ•˜๋‹ค๋ฉด, ์ฃผ๋ฌธ์€ 'immediate' (์ฆ‰์‹œ์ฃผ๋ฌธ)

๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด 'scheduled' (์˜ˆ์•ฝ์ฃผ๋ฌธ) ๋กœ ์ •์˜ํ•œ๋‹ค. ์ฆ‰์‹œ์ฃผ๋ฌธ์ด ์–ผ๋งˆ๋‚˜ ๋˜๋Š”์ง€ ๋น„์œจ์„ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค.

 

(๋น„์œจ ๊ณ„์‚ฐ์„ ์‰ฝ๊ฒŒ ํ•˜๋ ค๊ณ  1, 0์œผ๋กœ ์ •์˜ํ–ˆ๋‹ค.  1 = 'immediate', 0 = 'scheduled')

 

immediate percentage =  ( immediate ์ฃผ๋ฌธ๊ฑด์ˆ˜ / ์ „์ฒด ์ฃผ๋ฌธ๊ฑด์ˆ˜ ) × 100

 

* ์†Œ์ˆ˜์  ๋‘˜์งธ์ž๋ฆฌ ๋ฐ˜์˜ฌ๋ฆผ ์ฒ˜๋ฆฌ

SELECT ROUND((SUM(CASE WHEN order_date = customer_pref_delivery_date
        THEN 1 ELSE 0 END) / COUNT(*)) * 100, 2) AS immediate_percentage
 FROM Delivery