SQL服务器关联查询要取和
SQL Server correlated query want to take sum
select
SUM(Convert(int, (Select SUM(Convert(int, amount))
from ChargesType
where ChargesType.ID = Charges.ChargesTypeID))) as Amount
from Charges
Where Charges.RollNo = 1
这是我的查询;我想获得金额列的总和。
试试这个:
select
SUM(t.Amount) as Amount
from Charges AS c
INNER JOIN
(
SELECT Convert(int, amount) AS Amount, ID
FROM ChargesType
) AS t ON t.ID = c.ChargesTypeID
Where c.RollNo = 1
select
SUM(Convert(int, (Select SUM(Convert(int, amount))
from ChargesType
where ChargesType.ID = Charges.ChargesTypeID))) as Amount
from Charges
Where Charges.RollNo = 1
这是我的查询;我想获得金额列的总和。
试试这个:
select
SUM(t.Amount) as Amount
from Charges AS c
INNER JOIN
(
SELECT Convert(int, amount) AS Amount, ID
FROM ChargesType
) AS t ON t.ID = c.ChargesTypeID
Where c.RollNo = 1