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.…
SQL fill empty values in a column based on case when selection
So basically what I want to achieve is that if four columns are empty, one column contains a 1 as value and one column contains 0, then I want to entries in one column meeting the conditions with a default value (0.06077). Meaning: IF COL_A, COL_B, COL_C, COL_D IS NULL and COL_E = 0 AND COL_F = 0 then fill
Transpose rows to columns using multiple pivots
I am trying to transpose rows to columns without any luck . What I have now WEEK_NUMBER VAL9 VAL4 VAL5 VAL7 45 63.27% 28.58% 7.92% 0.23% 52 65.66% 26.16% 7.80% 0.38% 50 90.97% 8.45% 0.29% 0.29% 46 82.49% 12.43% 3.01% 2.06% 47 66.33% 29.53% 3.77% 0.36% 51 65.36% 31.83% 2.69% 0.11% 49 61.88% 28.29% 9.46% 0.37% …
Postgres Timestamp to DATE dd-mm-yyyy
im trying to insert select a casted timestamp in a date colum timestamp like 02-09-2021 00:00:00, and i need to convert this timestamp to date dd-mm-yyyy without hhmmss, i’ve tried select date(column) as newdate but when i check my table insert, it keeps like timestamp, all the solutions that i tried on…
T-SQL :: TRUNCATE or DELETE all tables in schema
I need to TRUNCATE or DELETE all tables in schema. I found this code: but on AdventureWorks it gives me: So I found this alternative code: But the result is the same: How to TRUNCATE or DELETE all tables in schema? Answer You simply need to wrap your “delete from all the tables” script with a R…
How to combine information from a main table and a log table in SQL Server
I currently have 2 tables in my database that i need to combine information from. One of them is a log table, that registers the status change of all products in the system. Structure example: ChangeDate Product LastStatus NewStatus 2021-10-01 A New Aging 2021-11-02 A Aging Ressuply 2021-11-25 A Ressuply OFF …
Query did not return a unique result
This is the query I have written: This is the output I am getting from the database: id versions 101 0.0 101 1.0 101 2.0 101 3.0 In my application, I am storing this result in but it gives an error saying “query did not return a unique result” How can I store this result? which data structure coul…
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 …
SQL: Substring until second character starting from right keeping left values
I have this filename AAAA_BBBBB_CC_HDDD_HGGG.csv and I’m trying to keep the values after the second underscore starting from the right. So i want to keep any values just before _HDDD_HGGG.csv This is my code: And this is the returned value: Instead of being AAAA_BBBBB_CC. Does anyone has a clue for this…