Hot answers tagged

3 votes
Accepted

Query for single return meeting multiple criteria and values

Start by joining the tables together, with the right filters on vendors in place. Looks like you need to group by subGrp and cusID to check for those Y, F, J values, then group again by subGrp to get ...
Charlieface's user avatar
  • 12.5k
2 votes
Accepted

Query to find when a specific current value changed

What you need to do is join table2 to it self and filter out the amount in when it is less meaning when it's changed to 0000 and then filter the date to leatest this one specialy for workID 251 cause ...
Ammar Talal's user avatar
2 votes

Snowflake won't allow an analytic function to be renamed

lag(...) over(...) is an entire expression, you cannot split it at will. The correct syntax is select a1 , a2 , lag(a2) over (partition by a1 order by a2) new_col_name from a
mustaccio's user avatar
  • 25.6k
2 votes
Accepted

Snowflake won't allow an analytic function to be renamed

SQL server has another syntax for creating tables from another select. Also you need to do that all columns named --drop table a; create table a ( a1 varchar, a2 varchar ); insert into a ...
nbk's user avatar
  • 8,000
1 vote

Select random records until a cumulative total is exceeded

In other words, the task is to get a list of records with a sum less then threshold, and one additional record to go over the threshold? This can be achieved by using with and union clauses: with ...
White Owl's user avatar
  • 757
1 vote
Accepted

How to update a Postgres row atomically, with a computed value that depends on the new values

The best practice is not to store redundant data in a database. My solution would be CREATE TABLE real_avg ( user_id bigint PRIMARY KEY, numer double precision, denom double precision ); ...
Laurenz Albe's user avatar
  • 50.3k

Only top scored, non community-wiki answers of a minimum length are eligible