In my database, I have two columns, products, and products_photos, where products can have many products_photos. What I want to do is a query that returns the products but with only one photo. I …
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 can I alter data type and datas in it, numbers separated with comma
I have table , that has field named AMOUNT , amount takes number, table has 1.4m records, i need to upgrade them all . I would like the change NUMBER to varchar and make look like amount datas comma separated , eg: 76543-> 76,543. How can I able to do it? Answer i need to upgrade them all Don’t; if
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(…
GROUP BY with Key:Value filters for each group
Given a table with following schema: RecordId ProcessId Data 80830F00-379C-11EA-96B7-372060281AFC 1 4.2 80830F00-379C-11EA-96B7-372060281AFC 2 445588662211448 80830F00-379C-11EA-96B7-372060281AFC 7 1 791F6D30-379C-11EA-96B7-372060281AFC 1 3.3 791F6D30-379C-11EA-96B7-372060281AFC 2 999999999999999 791F6D30-379…