Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

need modification in a query

$
0
0

HI All

I am trying to do leavers by location. I have my result set but what i want to do is if 3 rows are same then it should merge into one column and the total should be summed up to whatever it is. if two rows are different then it is fine

Example:- 

Total  Location  Wk_NO        Date

1Malta 52          2019-12-29
2Malta 52          2019-12-29
1Malta 52          2019-12-29

should be this

Total      Location        Week_NO         Date

4           Malta             52                   2019-12-29

Here is the screenshot 

SQL Code:-


select a.total,Location__c as Location,b.[Week Number],cast(b.[Week Ending] as date) as [Date]
from
(
select count(distinct fHCM2__Unique_Id__c)total, 
fHCM2__Location__c,convert(datetime,End_Date_Powershell__c,103) as [LeavingDate]
from Team_Member a
where fHCM2__Has_Left__c = 'True'
group by fHCM2__Has_Left__c,fHCM2__Location__c,convert(datetime,End_Date_Powershell__c,103)
)a
inner join 
Md_Date_Table b
on a.LeavingDate = b.Date

order by LeavingDate desc

Any help is appreciated

Thanks



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>