I have a table like this and so on What I ve done I got distinct count for every city and avg metric value But it is false Appreciate any help updated There is also an additional column id in varchar format Answer The answer here depends on this assumption: You always have exactly 3 metrics per ‘group&#…
Tag: sql-server
Migrate data from SQL Server to PostgreSQL
I have a stored procedure function as well as table in the SQL Server enterprise 2014. I also have data in the table. Now I need same table and data in PostgreSql(pgAdmin4). Can anyone suggest to me the idea to migrate data to POSTGRESQL or any idea on creating the SQL script so that I can use psql to run
sql server – checking existence for each row in insert
I need to do an insert and check for each row if the field “partita_iva” is already in this table, if yes the field “flag” must be 1, if not then must be 0. I did this, but it set 1 for all the rows, …
Aggregate quantity columns per distinct date in table sql
I want to sum quantity column from first date in table (2016-02-17 in this table) until per each distinct date in the table. Result relation should contains sum of quantities per each distinct date in …
How do I calculate amount of time in each week between two dates – SQL Server
[EDITED TO SIMPLIFY] I have 500+ records. All of which have a reference number, a start date, an end date and a total machining time. Ref StartDate EndDate MachineTimeHours 123 24/01/…
Select 3 and more duplicate rows in SQL Server
I’m learning the SQL Server and I got confused while selecting 3 and more duplicate rows in the SQL Server. I need to filter my data minimum 3 and more duplicate rows by using the SQL Server and I don’…
Running total over duplicate column values and no other columns
I want to do running total but there is no unique column or id column to be used in over clause. there are only 2 columns, name which has duplicate values and the no on which I want to do running total in SQL Server 2017 . expected result: Any help? Answer The following query would generate the output you
Fill table (PK column A, PK column B) with table of elements B, where column A does not have B – list pair
So, to me comes Table2 (PK Text) filled with elements FIRST, SECOND, THIRD, FORTH. I need to insert this element to TABLE1 where these elements are missing. TABLE1 +—-+——–+ | ID | Text | +–…
Merge the table based on date and condition
I have following table: In this table type will be 1,2,3,4.. here date and type both are composite key. I need to merge the row based if same date exist to single row and merge based on only below condition and grp col is based on running count of date. Answer Try GROUP BY FIDDLE DEMO Output
Assign default values in SQL Server dynamic pivot
Below is pivot query for my requirement. Below is my script for table creation scripts with data. Table_TraineeInfo is candidate registration details table, Table_Batch_Lookup is batch detail when batch start date and end date base on filling in pivot, Table_Attendance_Log is candidate attendance log. My curr…