|
| 1 | +# [Odd and Even Measurements](https://datalemur.com/questions/odd-even-measurements) |
| 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 | +## This problem was asked in Google Interview. |
| 10 | + |
| 11 | +## 🛠️ Problem Statement |
| 12 | + |
| 13 | + <b>Table Name : Measurements</b> |
| 14 | + |
| 15 | +| Column Name |Type | |
| 16 | +| ------------- | ------------- | |
| 17 | +| measurement_id | INTEGER | |
| 18 | +| measurement_value | DECIMAL | |
| 19 | +| measurement_time | TIMESTAMP | |
| 20 | + |
| 21 | +<b>measurement_id is the primary key of this table.</b> |
| 22 | +</br> |
| 23 | + |
| 24 | +Assume you're given a table with measurement values obtained from a Google sensor over multiple days with measurements taken multiple times within each day. |
| 25 | + |
| 26 | +</br> |
| 27 | + |
| 28 | +Write a SQL query to calculate the sum of odd-numbered and even-numbered measurements separately for a particular day and display the results in two different columns. Refer to the Example Output below for the desired format. |
| 29 | + |
| 30 | +</br> |
| 31 | + |
| 32 | +Definition: |
| 33 | +<br> |
| 34 | +Within a day, measurements taken at 1st, 3rd, and 5th times are considered odd-numbered measurements, and measurements taken at 2nd, 4th, and 6th times are considered even-numbered measurements. |
| 35 | + |
| 36 | +Return the result table in the order of measurement day. |
| 37 | + |
| 38 | +The query result format is in the following example. |
| 39 | + |
| 40 | + <details> |
| 41 | +<summary> |
| 42 | +Input |
| 43 | +</summary> |
| 44 | +</br> |
| 45 | + |
| 46 | +<b> Table Name: Measurements </b></br> |
| 47 | + |
| 48 | +| measurement_id | measurement_value | measurement_time | |
| 49 | +|-----------------|-------------------|---------------------------| |
| 50 | +| 131233 | 1109.51 | 2022-07-10 09:00:00 | |
| 51 | +| 135211 | 1662.74 | 2022-07-10 11:00:00 | |
| 52 | +| 523542 | 1246.24 | 2022-07-10 13:15:00 | |
| 53 | +| 143562 | 1124.50 | 2022-07-11 15:00:00 | |
| 54 | +| 346462 | 1234.14 | 2022-07-11 16:45:00 | |
| 55 | + |
| 56 | + |
| 57 | +</details> |
| 58 | + |
| 59 | +<details> |
| 60 | +<summary> |
| 61 | +Output |
| 62 | +</summary> |
| 63 | +</br> |
| 64 | + |
| 65 | +| measurement_day | odd_sum | even_sum | |
| 66 | +|-------------------------|----------|----------| |
| 67 | +| 2022-07-10 00:00:00 | 2355.75 | 1662.74 | |
| 68 | +| 2022-07-11 00:00:00 | 1124.50 | 1234.14 | |
| 69 | + |
| 70 | + |
| 71 | +</details> |
| 72 | + |
| 73 | +--- |
0 commit comments