Category "sql"

Joins on database engine vs on client-side [duplicate]

I am creating an API with express.js for a food app and I can't figure out what is the best (most efficient) way to query the data and send it

How to use WHERE statement on JSON stored in Presto SQL column to filter?

In Presto, I have data for a column in a table is as follows: header header 2 {Data: [{'item1': 'stuff1', 'item2': 'stuff2', 'item3': 'stuff3'}, {...}]} cell 2

Amazon Athena get data from the past one hour

I have some data rows in AWS Athena table and I am trying to get the data from the last 1 hour. I am using awswrangler, I will post my snippet below. Basically,

Return 0 if no row found in SQL Server using Pivot

Thanks everyone, and thank you @Aaron Bertrand, your answer solved my problem :) ! i am struggling to find a solution to my problem, here is my query in SQL Ser

Removing white space in column values of SQL o/p

Not able to remove white space from SQL query output used in pyspark code. I tried, trim,ltrim,rtrim,replace (multiple nested also) and regex replace. Any other

Total up transactions

I am using SQL Server Management Studio v18. I have an original transaction that might get adjusted either by amount or by commission%. I want a query to total

How do I create an array from a grouping of row_number()?

I have code that uses row_number() partitioned by date. I would like to create an array that contains data grouped by the row_number that is partitioned by date

spark-sql error column is neither present in the group by, nor is it an aggregate function can't solve with first_value, collected_list

I stuck with a spark.sql error that I couldn't solve with answers in stackoverflow, the point is I tried "first_value, collected_list" and they not solving erro

SQL query to get data if fields match or null if they dont

I need to get a list of users with their corresponding bed_id in case user has bed_id and fill with null if user doesn't have bed_id since there will always bee

If BULK INSERT fails because file does not exist then BULK INSERT Next file

I'm having an issue with BULK INSERT , the situation is the following : I've a folder path with probably 200 files in it but I've a table with 400 filenames tha

SQL executeUpdate() seems to commit data, but that is not the case. How can I find my error?

I curently work on few SQL queries (MSSQL 2O14), but only "SELECT" query works with executeQuery(). I had use execute() and executeUpdate() on "INSERT INTO" and

Get top n records for each group of grouped results

The following is the simplest possible example, though any solution should be able to scale to however many n top results are needed: Given a table like that b

problem with conditions in case when in SAS

I wanted to add a case when WPIS_ where if frm_code is one of the codes mentioned then we ASSIGNY W if not then B. I get "Syntax error" what I do wrong Rest cod

How can I Insert multiple rows with one query

I made a code allowing me to GET data from an API and insert it into a database. But I encounter a problem my api contains about 20 million data and to insert e

How to return multimap type with 3 tables (Android Room Databases)

I am trying to do a 3 way JOIN in my query for my Android Room Database. My tables relationships are: Table1 has a 1 to 1 relationship with Table2 Table2 has a

Update foreign key field in table to primary key values in another table

After adding SID to the TRANSACTIONS table, I need to update SID column in TRANSACTIONS based off STORE_NBR in the STORES table. Basically, I want to update the

I need to create a simple pie chart in SAS from a Proc SQL Table

I need to create a pie chart showing gender distribution for a state pulled through a macro variable. The code for the sql table looks like this: proc sql; crea

Trying to utilize a window function instead of this script

I'm trying to improve my query for this topic at hand. I'm trying to find the top 5 and bottom 5 growth rates per state from 2020 to 2021 in my org. The table h

What does a zero value coalesce function do?

I have been exploring dbt tools and I came across the following code snippet : coalesce(customer_orders.number_of_orders, 0) as number_of_orders I understand th

How to add a leading 0 in sql-server [duplicate]

I have to add a leading 0 in a column called houses, where it is a unique list of 3 digits, but I wanted have to add a leading 0 to it -->