I have a database table looks like this in the below, in SQL Server 2016: (the max rows for the same ProjectKey is 3) I want to write a query to be able to convert the above table to the following: If it can be achieved by writing a SQL query that would be great. Anyone can help? Thank you
SQL query in Java with enum return error of Incorrect integer value:
I get this error massage: java.sql.SQLException: Incorrect integer value: ‘xACxEDx00x05~rx00… the query is working, but if I put the category name (Category.Electricity) its return error. I call it with statement.setObject(…) meybe this is wrong..? the main class: the enum class: the method:…
INNER JOIN twice form the same table
I have 2 database tables that I want to JOIN. DB table 1 had football fixtures in it. So Team A plays Team B and the score was. The data comes from an API and in this DB table the teams are numbers instead of actual names. In the second DB table I have a list of all the teams
Flag items not having the specified combination in a column
I need to flag ID#s not having a specified combinations of DC and Storage Locations. For example: Articles must have the following combinations for each DC: DC Storage Location DC01 ABC, BCA, DCA DC02 ABC, BCA DC03 ABC, DCA My desired outcome would be the below as I’d like to show the Storage Location m…
SQL, retrieving only entries that all the IDs of its many-to-many relation are in an array
need some help with a SQL query. Below I wrote an example of what I want: I need to retrieve entries that the user has privileges to see all of its components. The privileges are stored in an array, for example, I’m a user with the following privileges: [1,2,3] In the database, I have a table with the f…
SQL query to remove duplicates from single column based on latest date
I have a table where I have duplicate values in just one column, and I want to remove those value using the column which has timestamp values. So the value which has latest timestamp should be in the expected result. For example, using the below table column1 is varchar, column2 is timestamp Looking at the ab…
Cycle detected while executing recursive query
I am using CTE recursive query to get below output but don’t know why it is throwing “cycle detected while executing recursive WITH query”. Can anyone please tell me where is wrong with my query? my query: SELECT order_id, product_id, quantity FROM cte; table/data script: Answer In the recur…
Redshift – How to use column in one table as pattern in SIMILAR TO
I have a problem where I have two tables. One table constains urls and their information and another groups of urls that should be grouped by a pattern. I have tried something like this bearing in mind that url_patterns will only have one row per group. The main problem here is that it seems that applying SIM…
SQL Server: join data but in single row
I have a table Invoice that looks similar to this: order_id completed_at subtotal discount_amount handling_amount 100 07/01/2021 10.09 0 0 101 07/04/2021 200.30 0 0 102 07/04/2021 54.10 0 0 103 07/06/2021 12.00 0 0 And I have another table InvoiceDetail: order_id product_id qty amount 100 1234 1 1.09 100 Ship…
ActiveRecord having count query condition
I have 2 models : Conversation and Message I need to retrieve all conversations that belongs to a Brand and where there are at least one message from the brand and one message from an influencer This is my query : But i get conversations that doesn’t have messages from both… What am i doing wrong …