|
| 1 | +# Restaurant Growth |
| 2 | + |
| 3 | +[](https://github.com/thecoddiwompler/SQL-Practice-Questions/tree/main) |
| 4 | +[](https://github.com/thecoddiwompler?tab=repositories) |
| 5 | +[](https://github.com/thecoddiwompler) |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 🛠️ Problem Statement |
| 10 | + |
| 11 | + <b>Table Name : Trade_tbl</b> |
| 12 | + |
| 13 | +| Column Name |Type | |
| 14 | +| ------------- | ------------- | |
| 15 | +| TRADE_ID | varchar(20) | |
| 16 | +| Trade_Timestamp | time | |
| 17 | +| Trade_Stock | varchar(20) | |
| 18 | +| Quantity | int | |
| 19 | +| Price | Float | |
| 20 | + |
| 21 | +<b>trade_id is the primary key for this table.</b> </br> |
| 22 | +This table contains data about trading of Stocks at some exchange. </br> |
| 23 | +</br> |
| 24 | + |
| 25 | +Write a SQL to find trade couples satisfying the following conditions for each stock : |
| 26 | + |
| 27 | +1. The trades should be within 10 seconds of window |
| 28 | +2. The prices difference between the trades should be more than 10% |
| 29 | +</br> |
| 30 | + |
| 31 | +The query result format is in the following example: |
| 32 | + |
| 33 | + <details> |
| 34 | +<summary> |
| 35 | +Input |
| 36 | +</summary> |
| 37 | + </br> |
| 38 | + |
| 39 | + <b>Table Name: Trade_tbl</b> |
| 40 | + |
| 41 | +| TRADE_ID | Trade_Timestamp | Trade_Stock | Quantity | Price | |
| 42 | +|----------|-----------------|------------------|----------|-------| |
| 43 | +| TRADE1 | 10:01:05 | ITJunction4All | 100 | 20.0 | |
| 44 | +| TRADE2 | 10:01:06 | ITJunction4All | 20 | 15.0 | |
| 45 | +| TRADE3 | 10:01:08 | ITJunction4All | 150 | 30.0 | |
| 46 | +| TRADE4 | 10:01:09 | ITJunction4All | 300 | 32.0 | |
| 47 | +| TRADE5 | 10:10:00 | ITJunction4All | -100 | 19.0 | |
| 48 | +| TRADE6 | 10:10:01 | ITJunction4All | -300 | 19.0 | |
| 49 | + |
| 50 | + |
| 51 | +</details> |
| 52 | + |
| 53 | +<details> |
| 54 | +<summary> |
| 55 | +Output |
| 56 | +</summary> |
| 57 | +</br> |
| 58 | + |
| 59 | +| tradeid1 | tradeid2 | price_difference | |
| 60 | +|----------|----------|------------------| |
| 61 | +| TRADE2 | TRADE1 | 25 | |
| 62 | +| TRADE3 | TRADE1 | 50 | |
| 63 | +| TRADE3 | TRADE2 | 100 | |
| 64 | +| TRADE4 | TRADE1 | 60| |
| 65 | +| TRADE4 | TRADE2 | 113.3333 | |
| 66 | + |
| 67 | +</details> |
| 68 | + |
| 69 | +--- |
0 commit comments