Query to get the Employee name and their manager's name from the same table in SQL Server
Below is Employee Table
SELECT e.employeename, m.employeename AS ManagerName FROM Employee e JOIN Employee m ON e.ManagerId = m.EmployeeId
Below is Employee Table
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestrictedreduce accept initial value, here in our sum of ages, we pass 0 as the initial valuereduce iterate over each value and add the sum each time with their previous sum value. Thus we return the sum at each step and that sum get added with the next age value.For the person array, lets group the objects using the color value. In our object, there are two blue color object and one green color object.
Steps to create the groupBy function,
{
"blue": [
{
"name": "Jim",
"color": "blue",
"age": 22
},
{
"name": "Sam",
"color": "blue",
"age": 33
}
],
"green": [
{
"name": "Eddie",
"color": "green",
"age": 77
}
]
}
Reference:https://learnwithparam.com/blog/how-to-group-by-array-of-objects-using-a-key/