Say I have the following table in MS SQL Server: Make Model Year Honda Accord 1997 Honda Accord 1997 Honda Accord 1997 Honda Civic 2001 Honda Civic 2005 Honda Civic 2005 Toyota Corolla 2010 Nissan Pathfinder 1997 I want to be able to retrieve the count for the unique combination and get the results like the f…
Tag: sql-server
SQL. Join with filter and offset
I need to create a SQL query that will return images with tags. The result should be ordered by some column and filtered by UserID and tags. The result should be paginated. There is a SQL statement This request is not working as expected. I expect to get 50 images, but they will be combined with tags and the …
Count unique values in a table with group by, with and without where condition
I have a table: FUND DATE ID POST ACAT Friday, January 1, 2021 10058 5056 ACAT Friday, January 1, 2021 10058 5056 BCAT Friday, January 1, 2021 32598 5004 ACAT Monday, February 1, 2021 10058 5056 MISS Monday, February 1, 2021 10058 5056 CCAT Monday, February 1, 2021 32598 5004 DCAT Monday, March 1, 2021 10058 …
Using SQL to Return Entire Paragraph if a word is found
I would like to return all the words surrounding the search term in a varbinary text enabled column. For example, if the word crisis is found, I would like to return the paragraph or at least 10 words on each side of the searched word. I am able to use the free text feature but I’m stumped as to how
Select info from row to another row
I have this select on a view: And get this: And I want that the last row be like this: That is, the values of all columns equal to the other rows, except column ‘C’ and column ‘D’. The value of column D is obtained from T2.D How can I do? Thanks. Answer Without any sample data to use I
Sql – Query to calculate no. of buyers monthly
i would really need your help in creating a query where i can show the number of buyers who made more than 1 order in a month for the period January 2017 to December 2017. Also, the no. of these buyers that didn’t order again within the next 12 months. Below is sample my data. Date CID (customer id) Ord…
Query to display Employee and Manager
I have to write a SQL Server query to display the employee last name and his respective manager’s name, as given below. These are the schema for the two tables. Expected Output : I tried this code but its not right Detailed Schema: Schema Answer I guess something as simple as this should do it How it works: T…
(SQL) Create Table with Distances from Separate Table with XY Coordinates
I am trying to create a table that will have unique distances between slot machines based on the following dataset. I know I first need to calculate my distances and the only way I currently know how would be to use the following code: But this obviously only returns the distance between the first two machine…
SQL – % Breakout by Hour
I’m trying to write a query that will break out what percentage of time is utilized within a hour given a time range. Sample data: declare @date table(id int, Start_time time, End_time time) …
T-SQL – subqueries on rows grouped by ID to create a summary table
I have a table “MyTable” with an id and two int fields “A” and “B”: MyTable +——-+—–+—–+ | ID | A | B | +——-+—–+—–+ | 99 | 0 | 1 | | …