Take - Home - Test 1
Take - Home - Test 1
Notes:
N/A
Similarity Check
Status: not found
No similar solutions have been detected.
Test score
13%
Tasks in test Score Impact
1 McqMssql1 59% Low
Submitted in: Multiple-choice questions
2 SqlCardPayments 0% Regular
Submitted in: SQL (PostgreSQL)
3 ABString 0% Low
Submitted in: Python
Tasks Details
MX Data ETL - Python – Alejandra García Román – task 1 of 3
A set of easy questions about Microsoft SQL Server and T-SQL. 59 Not assessed Not assessed
You have written the following SQL query, which calculates the total value of each customer’s orders:
You need to modify this query in order to nd only those customers whose orders exceed a total value of 1000. How can you do that?
A: Add the following line after the line with the FROM statement:
D: Add the following line after the line with the FROM statement:
A: 1
B: 2
D: There is no limit.
You want to concatenate the results of three queries into a single result set. Additionally, all duplicates should be removed. Which operator
will you use?
A: INTERSECT
B: UNION
C: UNION ALL
D: EXCEPT
You wrote an INSERT statement that inserts data into a dbo.Order table with an auto-incremented/identity column. This column is called Id.
Now you need to read the value generated for the Id column for the row inserted by your INSERT statement. What should you do?
You need to convert an expression of one type into another type. However, if a conversion is not possible, you do not want an error to be
raised. Which function can you use?
A: CAST
B: TRY_CAST
C: CONVERT
D: TRY_CONVERT
How can you effectively nd the list of all triggers at the table level de ned in a given database?
A: You can use SQL Server Management Studio to browse all the tables one by one and, for each table, check if there are any triggers
de ned.
The problem is that it can only be executed once; i.e. if you try to execute it more than once, an error informing you that a given stored
procedure already exists will be raised. How would you x this issue so that the script can be executed once, twice or many times?
ALTER PROCEDURE …
The problem is that it does not return customers that have no orders. How would you x this problem?
You are working with a database that is case insensitive. You would like to change it so that all operations are case sensitive. What should
you do?
B: You need to change the collation at the database level. You can do that with an ALTER DATABASE COLLATE statement.
C: This option is set when a database is created and cannot be changed later on.
D: You need to change the collation at the table level. For each table in a database you need to execute an ALTER TABLE COLLATE
statement.
BEGIN TRANSACTION
In the end, you decided to roll back the transaction. What is the nal effect?
A: The INSERT and DELETE statements will be rolled back, but a new table will have been created in the database.
B: The rollback will not succeed because DML and DDL statements have been mixed in the script.
Given the history of transactions in a bank account, compute the nal balance taking the credit
card fee into account. 0 0 Not assessed
Task description
You are given a history of your bank account transactions for the year 2020. Each transaction was either a credit card payment or an incoming
transfer.
There is a fee for holding a credit card which you have to pay every month. The cost you are charged each month is 5. However, you are not charged
for a given month if you made at least three credit card payments for a total cost of at least 100 within that month. Note that this fee is not included
in the supplied history of transactions.
At the beginning of the year, the balance of your account was 0. Your task is to compute the balance at the end of the year.
Each row of the table contains information about a single transaction: the amount of money (amount) and the date when the transaction
happened (date). If the amount value is negative, it is a credit card payment. Otherwise, it is an incoming transfer. There are no transactions with
an amount of 0.
Write an SQL query that returns a table containing one column, balance. The table should contain one row with the total balance of your account
at the end of the year, including the fee for holding a credit card.
Examples:
1. Given table:
+--------+------------+
| amount | date |
+--------+------------+
| 1000 | 2020-01-06 |
| -10 | 2020-01-14 |
| -75 | 2020-01-20 |
| -5 | 2020-01-25 |
| -4 | 2020-01-29 |
| 2000 | 2020-03-10 |
| -75 | 2020-03-12 |
| -20 | 2020-03-15 |
| 40 | 2020-03-15 |
| -50 | 2020-03-17 |
| 200 | 2020-10-10 |
| -200 | 2020-10-10 |
+--------+------------+
+---------+
| balance |
+---------+
| 2746 |
+---------+
The balance without the credit card fee would be 2801. You are charged a fee for every month except March, which in total equates to 11 * 5 = 55.
In March, you had three transactions for a total cost of 75 + 20 + 50 = 145, thus you are not charged the fee. In January, you had four card
payments for a total cost of 10 + 75 + 5 + 4 = 94, which is less than 100; thus you are charged. In October, you had one card payment for a total
cost of 200 but you need to have at least three payments in a month; thus you are charged. In all other months (February, April, ...) you had no card
payments, thus you are charged.
2. Given table:
+--------+------------+
| amount | date |
+--------+------------+
| 1 | 2020-06-29 |
| 35 | 2020-02-20 |
| -50 | 2020-02-03 |
| -1 | 2020-02-26 |
| -200 | 2020-08-01 |
| -44 | 2020-02-07 |
| -5 | 2020-02-25 |
| 1 | 2020-06-29 |
| 1 | 2020-06-29 |
| -100 | 2020-12-29 |
| -100 | 2020-12-30 |
| -100 | 2020-12-31 |
+--------+------------+
+---------+
| balance |
+---------+
| -612 |
+---------+
The balance excluding the fee would be -562. You are not charged the fee in February since you had four card payments for a total cost of 50 + 1 +
44 + 5 = 100 in that month. You are also not charged the fee in December since you had three card payments for a total cost of 100 + 100 + 100 =
300. The nal balance is -562 - 10 * 5 = -612.
3. Given table:
+--------+------------+
| amount | date |
+--------+------------+
| 6000 | 2020-04-03 |
| 5000 | 2020-04-02 |
| 4000 | 2020-04-01 |
| 3000 | 2020-03-01 |
| 2000 | 2020-02-01 |
| 1000 | 2020-01-01 |
+--------+------------+
+---------+
| balance |
+---------+
| 20940 |
+---------+
You earned 21000 but you are charged a fee for every month. The nal balance is 21000 - 12 * 5 = 20940.
Assume that:
Copyright 2009–2022 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Source code
Analysis summary
The following issues have been detected: runtime errors.
Analysis
Example tests
example1 ✘ RUNTIME ERROR
First example test. tested program terminated with exit code 1
Correctness tests
corner_case ✘ RUNTIME ERROR
Zero or one transaction. tested program terminated with exit code 1
Check, whether in a given string all letters 'a' occur before all letters 'b'. 0 0 0
Task description
Write a function solution that, given a string S consisting of N letters 'a' and/or 'b' returns True when all occurrences of letter 'a' are before all
occurrences of letter 'b' and returns False otherwise.
Examples:
3. Given S = "aaa", the function should return True. Note that 'b' does not need to occur in S.
4. Given S = "b", the function should return True. Note that 'a' does not need to occur in S.
Copyright 2009–2022 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Source code
For example, for the input 'b' the solution terminated unexpectedly.
Analysis
Example tests
example1 ✘ RUNTIME ERROR
First example test. tested program terminated with exit code 1
Correctness tests
one_letter ✘ RUNTIME ERROR
Strings with only one character repeated N times. tested program terminated with exit code 1
ip ✘ RUNTIME ERROR
Strings in form 'aaa..abbb..b' with ipped letters on some substring. tested program terminated with exit code 1
Performance tests
small_random ✘ RUNTIME ERROR
Random strings. N <= 1000. tested program terminated with exit code 1