I need to write a query to select the manager and total salary of employees under the manager. The salary of employees should roll up to Manager based on hierarchy. Mgrid references to empid in the same table. Table : Employee Output should be ManagerName and Salary In the above example : M2 has M3, M4, M6 di…
Writing SQL Queries Workbench
I’m having some trouble with writing this query. This is what I have so far: Find the name of the customer that deposited the highest amount with one transaction (include the transaction amount). …
Find difference in quantity column of two tables
Suppose I have two tables, with a item name and quantity: Table 1 Item Name Quantity a 10 b 15 c 2 Table 2 Item Name Quantity a 45 b 2 I want to find the difference in quantity of items from …
Merge several rows into one if they have a gap less than a 5 seconds
I’m trying to find a SQL query that lets me to merge some rows into one from a table that have a gap less than 5 seconds. For example, I have a table like the following: So, I want to have a result like this: For John there are two rows that have a gap less than 5 seconds, so
Query Java doesn’t execute
I’m trying to execute a query on eclipse at my Java program, but it always exit with a exception and don’t execute the query, I read a lot of posts here but no one of them could help me with this. …
Merge not inserting new values
I’m trying to use MERGE to insert new values to a table only if they don’t already exists in the same table. This is the query I am using: MERGE [dbo].[TARGET_TABLE] AS Target USING (SELECT [NAME] …
ORDER BY DECODE: Decode won’t reorder the days like I want it to
I’ve got an assignment where I need to return a certain report and then order it by the day, but I need Monday to be day #1 (by default, Sunday is day #1 in SQL). Here’s my code for the report and the …
Setting transactional-table properties results in external table
I am creating a managed table via Impala as follows: This should result in a managed table which does not support HIVE-ACID. However, when I run the command I still end up with an external table. Why is this? Answer I found out in the Cloudera documentation that neglecting the EXTERNAL-keyword when creating t…
Is there any query to find duplicate records count corresponding to package_no column?
I have a table structure like this I Need to count duplicate road code corresponding to the column package_no I expect one record from the above table with a duplicate package p1 and road count with 1 Answer You have a consistency problem. In your initial description you say “duplicate road code corresp…
Snowflake how can we cast all fields of select query when unpivot is not detecting fields with a different types?
Following up on this question, I made the following script: It will help me transpose a temporary table to add all related fields into another table, where each field/value pair represent a row. The error I am getting out of this query is: SQL compilation error: error line 2 at position 77 invalid identifier …