[英]Group by one column and select more than one column Sql query
我需要按不止一列分组,但在特殊情况下:
我有一个(Payment_Type,Year,TotalMoney)
我只需payment_type(cash or credit)
获得总分组,我需要在查询中选择年份我该怎么做? 我的查询是:
select Payment_Type,Year,SUM(TotalMoney)
from table
where 1=1
group by Payment_Type,Year
我收到一条错误消息:
年不包含在聚合函数或 GROUP BY 子句中
select Payment_Type,Year(YourDateColumn),SUM(TotalMoney)
from table
group by Payment_Type,Year(YourDateColumn)
如果你的专栏被命名为 year 那么
select Payment_Type,[Year],SUM(TotalMoney)
from table
group by Payment_Type,[Year]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.