Skip to content

Drop a hive table named “union”

I am trying to drop a table names “union” but I keep getting an error. I am not sure who and how created that table, but nothing works on it, including describe or select. Using “hdfs …

Update statement within select statement

I am trying to write a query in which I update a counter based on other conditions. For example: with table 1 as (select *, count from table1) select box_type, case when box_type = lag(box_type) …

Substring, As, Count issue

I need to extract part of an ID Field (ParcelID) and then use the count field to count the number of times it is in the database. This is what I did: I created a view with the following: SELECT …

SQL – Join with window

I have this dataset of product sales: PRODUCT SALES YearMonth Client_ID 202103 1 202008 1 201807 1 202101 2 202011 2 …

SQL query returns 0 for COUNT(*) if no rows

I just got started with SQL and joined this forum recently, thus I’m still lacking the knowledge. Please do be considerate if I’ve made any mistakes. I intend to get the data from the past n days. For each day, the query will count the total rows and return the result. However, there are no record…

How to insert default value in unknown column

I have a function that INSERT INTO a table some data. I do not know how much columns the table has (let it be N). My func gets a list of N-1 params and then INSERT INTO … VALUES( *N-1 params* ) …

pgsql: filter column to get latest value

I have below query to pivot, how to get status value filtered on latest updated_on row for each obj_key select obj_key, max(updated_on) as updated_on, max(att.status) as status, COALESCE(max(…