I have the following table: In Table_1, (ID, Name) pairs can repeat and have any combination Table_1: ID Name Value1 Value2 1 John 34 45 1 John 15 78 2 Randy 67 12 2 Randy 40 46 1 Randy 23 85 2 Holmes 10 100 I want to find all information for all unique pairs. So the output should be:
Tag: sql
Removing rows based on a string in Snowflake (SQL)
Let’s say I had a table as follows: And what I want to do here is if an ID has a group and the same ID has the group-Direct, then the Direct row is removed. So what It should look like is: What happened? The only ones to change were ID = 001 and ID = 005. ID = 001
How to find the Employee names and their supervisor names if the table doesn’t have common numeric column like Employee_id or employee number in Mysql
If the table have only two columns with employee name and their supervisor column and if it doesn’t have any other numeric or number column with employee_number or employee_id, then how the results can be produced. I’m not getting logic to show the results. Code for creating table in Mysql: ItR…
Calculating checksum in Big Query
I have a query in SAP HANA like below. I am calculating check_sum based on some column in the table Now I have created the same table in Big Query. I want to calculate check_sum in Big Query and get the same result as in SAP HANA I have tried like below It says TO_BINARY function is not available. I
How to get a count of records by minute using a datetime column
I have a table with columns below: Customer Time_Start A 01/20/2020 01:25:00 A 01/22/2020 14:15:00 A 01/20/2020 03:23:00 A 01/21/2020 20:37:00 I am trying to get a table that outputs a table by minute (including zeros) for a given day. i.e. Customer Time_Start Count A 01/20/2020 00:01:00 5 A 01/20/2020 00:02:…
Filtering unique values
Consider the following table: Column_A Column_B Column_C 1 UserA NULL 2 UserB NULL 3 UserC 1 4 UserA 1 5 UserB NULL 6 UserB 2 7 UserC 2 I’d like to return all rows (Column_A, Column_B, Column_C) such that either: Column_C is NULL, or for every unique value in Column_C, return the first row with Column_B…
How can we achieve the below output (PostgreSQL)
I need to calculate the Numerator and Denominator values for one metric called Payments% and the formulae for numerator is count(distinct id) where menuaction in (‘Billpayment’, Renewal’) Denominator formulae is count(distinct id) and I need the below columns in output using postgresql datab…
SQL query with loop to collect 14 day averages
I am a python user, new to SQL. I am trying to make a new table that is the average of the “NumberValue” column between two dates from “RecordDate” column, and slide that date range so that the new table has columns “average” that is the average of “NumberValue”…
Checking the Oracle SQL DECODE function result against 0
I’m looking at some old PL/SQL code and I have dozen of DECODE functions written like this: DECODE(value_1, value_2, 1, 0) = 0 Now, I know these DECODEs make comparison between value_1 and value_2 and they return true or false based on the outcome of comparison. But, for the love of coding, could someon…
Sum values in two different tables and join results keeping the columns
I have two tables: one with downtime and the other with productive time. I want to have a table like this But I am getting this In the result, I am getting twice the downtime of the sum for the report 04102021-1, but as can be seen in the second picture, the value is present only once. The script I