簡體   English   中英

按一列分組並選擇多列Sql查詢

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM