Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago. Improve this question Given both give the same result and from the same data. Does adding the co…
Tag: sql
Query to Id referencing to an ‘Id’ to the same table
I have a table AMZ_EMPLOYEE_DETAILS with Employee Id, Employee Name and Supervisor1 and Supervisor 2. The Supervisors are employee itself but represented by their name. My task was to replace the Supervisor names with their Ids. I have used the following query to obtain the solution but it uses sub-queries an…
Reformatting multi-feature timeseries data with SQL
I have a table that has the following formatting: id | uid | created_at | feature | value 1, 1, 2019-10-1 20:26:32, ‘weight’, 155.0, 2, 1, 2019-10-1 23:26:32, ‘weight’, 150.0, 3, 1, 2019-10-2 10:00:…
SQL – joining 3 tables and choosing newest logged entry per id
I got rather complicated riddle to solve. So far I’m unlocky. I got 3 tables which I need to join to get the result. Most important is that I need highest h_id per p_id. h_id is uniqe entry in …
Query to return one result, but have a count of other field
I have multiple fields within my SQL table(Microsoft Access) and have created a form that will allow users to search for a serial number. This search should use the value of a text box to search one …
How to create index on records for last 90 days in Postgres Making now() immutable
I have a case where due to speed issues I only want to create the index on records for last 90 days. When I try to create index like this: create index if not exists …
SQL Server – Close external port and work as localhost when sql server and application are on the same server
My database and my web application are at the same server at the moment and I would like to access SQL Server as localhost and close the SQL Server port for remote connections. This is my current …
Concat rows for employee roles
I’m using SQL Server. Looking for similar functionality as GROUP_CONCAT or listagg functions provided in other Databases. Seems like STUFF function is provided to concat rows. Here’s my attempt. Employee Role EmployeeRole Expected Output Answer In SQLServer 2017, you can use aggregate function STR…
Trying to use the condition in a case when expression as the result
I have a CASE expression and for one of the WHEN clauses, I’m selecting data from a table and checking if it exists. If it exists, I want to return one of the columns from that row in the THEN …
SQL/PowerBI search in a particular line (not row) of data
I have a column with multiple line data. It shows as one line in SQL Server but multiple lines in Power BI so I guess there are some special characters in there to tell Power BI where the new line starts. What I want to achieve is to search the second to the last line instead the whole cell, to