I have Order data for 2 customers and their order. And I am trying to calculate what the sum for the price is for every customter for that specific order only for product N Table: This is my query: For some reason I do not understand it gives me several rows per same customer. I am trying to get only
Create Continuous Enrollment islands for a certain sub-population
My end goal is to create islands of continuous enrollment days for each CLIENTID for a single sub-population: ‘Adult Expansion’ for calendar years 2019 and 2020. A CLIENTID can be associated with …
Get sum of column with distinct id in SQL
I am trying to get sum of the amount on distinct ext_id. Id Ext_id amount 1 234 5 2 234 5 3 235 10 4 236 8 5 236 8 Select SUM(amount) from Table1 — this will get me sum of all => 36 I want just sum of distinct Ext_id which should be 23. Can someone help me with this?
SQL JOIN, all from t1 and all from t2 except what’s common to t1
I need all entries from Table A and all entries from Table B that are NOT common to table A. I have 6 common fields. How do I go with this? I tried select … from Table A left join Table B, it missed some values from Table A. Tried also right join, full join…Any pointers on how to do
JPA query is throwing a ‘not found’ error for column that isn’t in query
I’m trying to call for only specific columns in my DB but the query is throwing an error saying that the next column is not found (even though it’s not in the query) Is there a problem in the join that’s doin this? I’m a bit perplexed as to this problem. JPA Query from ConnectionReques…
How to show a table with custom message in SQL?
Is it possible to show a message before a table in MS SQL Server? Assuming this have a table of NAMES with columns firstName and lastName This code/query shows only the tables firstName and lastName without the message ‘This is a list of names’ Answer Run the query from SSMS with the Results to Te…
MSSQL COALESCE function with multiple non null values
I am trying to get data (T_Stamp, Destination, Weight, Line) from two tables using variable time intervals and a destination selection. This is going into an Ignition SCADA. My SQL code below works for most cases except when there are entries into both tables with the same timestamp. In those cases it shows o…
Retrieve last record in a group based on string – DB2
I have a table with transactional data in a DB2 database that I want to retrieve the last record, per location and product. The date is unfortunately stored as a YYYYMMDD string. There is not a transaction id or similar field I can key in on. There is no primary key. DATE LOCATION PRODUCT QTY 20210105 A P1 4 …
Replace NULL values per partition
I want to fill NULL values in device column for each session_id with an associated non-NULL value. How can I achieve that? Here is the sample data: +————+——-+———+ | session_id | step …
Using columns in window function that are not in Group By, I get : SQL compilation error: [COLUMN_A] is not a valid group by expression
I’ve seen a lot of questions about this error, the closest one (as it’s using window function) to my issue would be this one My issue is that I use columns in the windows function that are not …