Skip to content

Aggregation level is off (Postgresql)

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

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?

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…

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 …