[英]How do I stack a column next to each other in SQL?
I have a employee table:我有一张员工表:
I want to get the avg salary of male and female but I want the results to be next to each other rather than in the same column.我想获得男性和女性的平均工资,但我希望结果彼此相邻而不是在同一列中。 Right now this is what I get:现在这就是我得到的:
But I just want the results to look like this:但我只想让结果看起来像这样:
How do I tweak my query?如何调整我的查询?
Please try below query:请尝试以下查询:
select coalesce(avg(case when sex='M' then salary else null end),null) as Male,coalesce(avg(case when sex='F' then salary else null end),null) as Female
from employee
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.