Timeline for Group by multiple columns, agregate others and select all in SQL Server
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 27, 2018 at 22:36 | comment | added | jyao | My bad. "Cross apply" does not work here. Re-write the answer with runnable test case. Thx @ypercubeᵀᴹ | |
Feb 27, 2018 at 22:34 | history | edited | jyao | CC BY-SA 3.0 |
Redo the answer
|
Feb 27, 2018 at 22:21 | comment | added | ypercubeᵀᴹ |
Reading this again, I don't see how it would work. The GROUP BY would forbid the t columns to appear in the SELECT list. Have you tried this? GROUP BY is done after the CROSS APPLY but your code suggests you are trying to do the GROUP BY before the CROSS APPLY. I suggest you use a derived table, to do the GROUP BY first.
|
|
Feb 27, 2018 at 22:17 | comment | added | jyao | @ypercubeᵀᴹ, yes, you are right. Just fixed it. Thx | |
Feb 27, 2018 at 22:16 | history | edited | jyao | CC BY-SA 3.0 |
typo change
|
Feb 27, 2018 at 22:15 | comment | added | ypercubeᵀᴹ |
You need to alias the columns in SELECT and GROUP BY in the main query. Because s and T have columns with the same name.
|
|
Feb 27, 2018 at 22:03 | history | answered | jyao | CC BY-SA 3.0 |