Skip to content
Advertisement

Tag: tsql

Using one query’s result into another

I have this query which shows the below result, I want to use this MarksObtained and take out min, max and avg of each course and show it with the second query (have provided below). This is the second query So it will basically show min, max and avg of each course achieved by the students. What I want: Sample

Find names based on max number dynamically in SQL

I have a data set like this: Table A: What’s the maximum number of Place on which a Partner has spent money and who are these Partners? Display only the Partners reaching this max number I tried this: But I feel like its not the right logic. What am I missing? Answer There’s really no need for your subquery, it

T-SQL Logic (Where exists one column but not the other)

I need a bit of logical help in writing a query. Here is the set up. I need a query that returns all records from main_table where the id of main_table matches the id of sub_table, but seq of main_table does not match seq of sub_table. Expected result is id seq A1 3 A2 2 A2 3 My attempt What

Does Adding Indexes speed up String Wildcard % searches?

We are conducting a wildcard search on a database table with column string. Does creating a non-clustered index on columns help with wildcard searches? Will this improve performance? Proposed Index: for this query Currently using Microsoft SQL Server 2019. Answer Creating a normal index will not help(*), but a full-text index will, though you would have to change your query

Modify query so as to add new row with sum of values in some column

I have table in SQL Server like below using below code: How can I modify my query in SQL Server so as to add new row with sum of values in col2? So I need something like below: Answer You could use ROLLUP for this. The documentation explains how this works. https://docs.microsoft.com/en-us/sql/t-sql/queries/select-group-by-transact-sql?view=sql-server-ver15 —EDIT— Here is the updated code demonstrating how

Advertisement