Query to load the sequence for e_uuid 13 & 15 Then I want to merge into the same table for e_uuid 14 & 16 For 14: It should check e_uuid = 13 and maximum seq_cnt. Here(after executing my merge statement) maximum seq_cnt is 2 then the seq_cnt for 14 will come as 3 & 4. And if there are any
Tag: sql
How to get NULL or Zero values in SQL Server results set
Trying to get the output of all mentioned accounts(total of 9) even though there are no existing records for the GB.periode = 11 Tried using ISNULL(SUM(GB.bdr_val), 0) but still I’m only getting output for GB.reknr = 5210 OR GB.reknr = 5211 OR GB.reknr = 5250 OR GB.reknr = 5340. I have a sample DB layou…
I am having Issues counting values in a row with separators using SQL
I am new to snowflake and trying the count the number of values in a row with separators using SQL. I am not sure how to go about it. I’ve googled solutions for this but have not been able to find one. table name: Lee_tab user names id01 Jon;karl;lee; id02 Abi;jackson; id03 don; id04 what I want to achi…
Given a table of numbers, can I get all the rows which add up to less than or equal to a number?
Say I have a table with an incrementing id column and a random positive non zero number. id rand 1 12 2 5 3 99 4 87 Write a query to return the rows which add up to a given number. A couple rules: Rows must be “consumed” in order, even if a later row makes it a a perfect
SQL Server 2017 STRING_AGG Order By
I’m using SQL Server 2017 Microsoft SQL Server 2017 (RTM-GDR) (KB4583456) – 14.0.2037.2 (X64) Nov 2 2020 19:19:59 Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro 10.0 (Build 19042: ). I’m trying to sort the results of the STRING_AGG function. This works …
How to make POSTGRESQL query based on first 2 parameters and latest third parameter
I have DB: I need to make query request for last year(or last 12 months) group by Client_id, Version and latest date(!) for them. For example: This is what I have right now: And I’m getting result for EVERY DAY. If I’m removing DATE from group by, its complaining that Date should be in Group by. I…
select all “groups/partitions” where parameter is found
Without going into too much detail – I need to create groups (grouped on a specific field) of data and then display all GROUPS of records that contain a parameter. I need all records in a GROUP even if some do not match the parameter. Any GROUPS where no records contain the parameter would be suppressed…
Subquery must have alias despite having alias?
I have an Alias at the bottom (AS crypto). However, I still get the “subquery in FROM must have an alias” error. And then HINT “For example, FROM (SELECT …) [AS] foo.” I see many other posts that say to “just add AS _” as an alias, but mine still isn’t working. …
Sequelize raw query update array of objects as replacements
I am using sequelize (postgres) and I need to properly escape a query like this: Sample input.pets: Does anyone have an idea how to achieve this with replacements? I have found a thread on github which suggested something like this: However, a 2d array is being used here not an array of objects. Is there a wa…
Grouping rows over common data in a column and min max start/end date via cursor fetch method
I have a stored procedure with a couple of input parameters Input parameters: Result set: AuxTable is not the final intended table, it’s just being displayed for debugging/troubleshooting. MsgLinkId MyRowId WO_ID SourceUnitName MaterialName BatchID UnitofMeasure Segment1 Segment2 Segment3 Segment4 Segme…