Anything in the GROUP BY clause must also appear in the SELECT clause.
There are several ways of rearranging this with sub-queries etc but below is a solution using CTEs (
Common Table Expressions[
^])
-- Get the grouped data from TBuy into CTE T1...
With T1(Kala, tedadkala, andaz, kalakol)
AS
(
SELECT Kala, Count(Kala), SUM(Andaze), SUM(Kol)
from TBuy GROUP BY Kala
),
-- Get the grouped data from TSel into CTE T2...
T2(Kala, tedadkala2, andaz2, kalakol2)
AS
(
SELECT Kala, Count(Kala), SUM(Andaze), SUM(Kol)
from TSel GROUP BY Kala
)
-- Use the CTEs in the overall query
select
dbo.TAnbar.Anbar as anbar,
dbo.TAnbar.Kalatype as noekala,
dbo.TKala.Cod as cod,
dbo.TKala.Kala as kala,
dbo.TKala.Vahed as vahed,
dbo.TKala.Toz as tozi,
dbo.TKala.Mojodi as mojodi,
dbo.TKala.Pic as pict,
tedadkala,
andaz,
kalakol,
tedadkala2,
andaz2,
kalakol2
From dbo.TAnbar
inner join dbo.TKala on dbo.TAnbar.Anbar = dbo.TKala.Anbar
inner join T1 on T1.Kala = TKala.Kala
inner join T2 on TKala.Kala = T2.Kala
where dbo.TKala.Kala = @kala
--NB NO group by here