Unable to Subtract Dates SQL Server

Using the sample data you posted (and adapting it slightly), here is my attempt to solve the problem: SELECT BASESCORE, Datediff(dd, MINDATE, MAXDATE) FROM (SELECT BASESCORE, Cast(Max(DATETIME) AS DATETIME) MaxDate, Cast(Min(DATETIME) AS DATETIME) MinDate FROM table1 GROUP BY BASESCORE)T You can take a look at the full working version on SQL Fiddle. Let me know … Read more

What is the result of following SQL Query?

Answers (b) and (d) are totally wrong. The query won’t return any rows from TableA. If there are any matching rows are found in TableA, those rows get excluded by the condition in the WHERE clause. (Note that any value of columnName that satisfies the equality comparison in the ON clause will be non-NULL, and … Read more

How to get percentages of maximum counts?

SELECT TeamName, Count(TeamName) AS Count FROM table GROUP BY TeamName You need to use the Count Function – To count the team name And you need to use group by to determine how you want the counts to be grouped Edited Answer. SELECT TeamName, Count(DISTINCT CASE WHEN WorkInfo = 1 THEN SlNo end) AS Count1 … Read more