Posts

DE SQL Hiring Questions | 106

DE SQL Hiring Questions | 106 Q: I have a table with customer ID, session ID, and session date. Another table has transaction date and customer ID. I want to know the days between the session date and the next transaction, previous transaction, and closest transaction.  * A customer can have multiple transactions before and after session. This problem requires calculating time differences between session dates and transaction dates for each customer. Here's a SQL solution: SQL Solution: WITH NextTransactionDates AS ( SELECT customer_id, session_date, transaction_date AS next_transaction_date,           ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY transaction_date) as rn_next,      DATE_DIFF('day', session_date, transaction_date) AS days_to_next_transaction FROM sessions s JOIN transactions t ON s.customer_id = t.customer_id WHERE session_date <= transaction_date    ...

Python Hiring QnA | Py101

  Python Hiring QnA | Py101 1. Count the number of vowels in a string Write a Python function to count the number of vowels (a, e, i, o, u) in a given string. Solution: def count_vowels(text): vowels = "aeiouAEIOU" count = 0 for char in text: if char in vowels: count += 1 return count # Example usage string = "Hello, World!" vowel_count = count_vowels(string) print(f"Number of vowels in '\{string\}': {vowel_count}") 2. Reverse a given string Write a Python function to reverse a given string. Solution: def reverse_string(text): return text[::-1] # Example usage string = "Python" reversed_string = reverse_string(string) print(f"Reversed string of '\{string\}': {reversed_string}") 3. Largest number in a list using sort and loop Write a Python function to find the largest number in a list using both sorting and looping. Solution: def find_largest_number(num...