Skip to content

Tag: sql

Numbering duplicate rows in bigquery

I’m trying to number rows in which column a and column b is a match and when they occur again regardless of the date. The dataset looks like this and I want the row_number column: rider driver date row_number jim joe 2020-10-20 1 jim joe 2020-10-28 2 jim jack 2020-10-29 1 jim joe 2020-10-31 3 john jane …

Joining on the same table to get 2 different amount values

I want to get the total amount of a funding source (dim_6) against 2 different account codes (1301 AND 1300). Below is the query that I designed. The above query doesn’t return the correct sum of amount and it doesn’t match the value of amount if I try to run a simple SQL query against 1 account c…

SPROC with Outer-Apply returns too many rows

I have a complicated enough SPROC, which I modified to return a few more columns (from additional tables). What I wanted is to have this SPROC still to return the same amount of rows and the same data, but to fill in new columns (if data exists) as well, for those rows. My modification does fill new columns, …

Is there anyway to test the function in SQL?

I have following problem. I’ve made an function which checks dates, warehouse if it’s full, etc.. Here is the code and I’ve added comments so it is more clear and understanble: So basically if I run only the function I don’t get any error. But when I run it with the test date I get fol…

UPDATE VALUES OF COLUMN IN POSTGRESQL

I have 4 tables: what i want is to update table1 with the salary values from matchsal table with conditions in the others tables, i tried this query: and i got this error: ERROR: more than one row returned by a subquery used as an expression SQL state: 21000 Answer I found the answer ^^” It is simple th…

MySQL: Extract Select in “Module”

Assuming the following SQL statement: The there a way to modularize the statement, for instance, extract the second select statement in a file and call this file instead of writing the whole query? Answer I found a way to reuse SQL. Its possible via SQL-Functions and SQL-Procedures