Skip to content

Tag: sql-server

Include Medians for grouped query .

I have this query that I need to graph. The graph will show Total patients, patient Longest wait (minutes) and patient Median wait for each location. I need to include Medians in my query, and that is where I am stuck. Example Raw Data: Query I have so far w/o Medians: Output: I need help getting a last colum…

SQL Query for multiple Pivot on same column

As per my requirement, I need to apply pivot twice on same column to get different values as column header. Please see below how the data is present in table and expected results. Table Question Response TranslatedResponse activityid createdon Reason Testing testaus 1 01-01-2022 EMail abc@gmail.com abc@gmail.…

Count all the entity between periods – SQL Server

I want to count all the entities that created between August 1 until May 31 for each year. (academic year) I am successful counting it monthly, but it’s not good enough: Can someone help me with this? Thanks. Answer you can try this : Explanation : when the month is small than 6 then it’s part of …

Data query to keep the common data

I have a table Table 1 : It the final table contains all data . ID and IDS are composite key table 2 : Its a pre final table which will upcoming data with incomplete information EXPECTED RESULT : Some IDs (ID+IDS) are in Table 1 and some are in Table 2 . I need to compare the data of

Timeserial not recognized built in function in MS SQL

I am trying to implement an SQL query that gets records between today’s fixed timing 18:00 and yesterday’s fixed timing 18:00 based on a Date time column that I have in my table. I tried this query But, it’s throwing an error Timeserial is not a recognized built-in function name. Any ideas p…

Select max entries in a range in SQL server

I have a salary column where I have to select between range of 10000 and 20000 and also the top rows of max salary. Column I have: Rows I want to select I can use top n rows but that will apply on to this column. What I want to do is, say if this column has 2 rows that