Skip to content
Advertisement

Tag: sql-server

Distincted ids for grouped values

I want to count the distinct ids in each numb and store them in a column : Tried this: Receive this output: As you can see COUNTER columns has the count of distincted ids but for all NUMB I want to output this: 1515 has 2 ids 1921 has 1 id 2121 has 2 ids I tried also to place

Concatenate from rows in SQL server

I want to concatenate from multiple rows Table: |id |Attribute |Value | |——–|————|———| |101 |Manager |Rudolf | |101 |Account |456 | |101 |Code |B | |102 |Manager |Anna | |102 |Cardno |123 | |102 |Code |B | |102 |Code |C | The result I’m looking for is: |id |Manager|Account|Cardno|Code | |——–|——-|——-|——|———-| |101 |Rudolf |456 | |B | |102 |Anna |

Recursive SQL query for finding matches

I have 5 SQL Tables with the following columns: As input data I have employee_id and request_id. I need to figure out whether the employee has access to the request (whether he’s a manager or not) We cannot use ORM here since app’s responsiveness is our priority and the script might be called a lot. Here’s the logic I want

Add hours/minutes to datetime

I’m having an issue on how to add the Offset to the EventDateTime. Is there a way to do this? I would convert it to a decimal number but cannot because 5:30 is not 5.3 hours, it’s 5 hours and 30 minutes. The data is shown below with the expected output. Please help if possible. Sample Data: Expected Outcome: What

Finding last and second last date and corresponding values

Consider the following schema (fiddle): For each meter.id I need to find the latest reading date, value, and the value difference vs previous reading. For the sample data my output would look like this (plus some other columns from meters): meterid latest value delta value 1 20090403 399 99 2 20090403 288 44 3 20090403 555 null 4 20090303 600

MS SQL return single row case dataset without GROUP BY clause

I have a data set of ActivityDate which is a datetime field and EngineHours which is a decimal field. I want to return a single row of data that brings back the average number of EngineHours on each day of the week. The dataset is pretty big so the best performance is likely to be the most ideal, the script

How to join two tables where Columns are not matching in SQL

I have two different tables and in the select query I need to bring the SUM of the other column but both the tables have some similar data but still in the query output values are not coming fine. I am using below query :- Query 1 Query 2 Query 1 output COUNTRY BUDGET_SALES MY 20463355.16 SG 41095952.67 Query 2

Advertisement