开发者

SQL : SubQuery with Group By [duplicate]

开发者 https://www.devze.com 2023-04-08 05:22 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: SQL : How can I use sub query in a query with group by section?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

SQL : How can I use sub query in a query with group by section?

Some one help me please . SQL Server cant recognize t1.sen in subquery . Error message : The multi-part identifier "t1.sen" could not be bound.

select
    t1.sen,
    sum(t1.d_rooz)as d1,
    sum(t1.d_shab)as d2,
    开发者_JS百科sum(t1.d_rooz+t1.d_shab) as d_sum,
    Round((sum((1000*(t1.d_rooz+t1.d_shab))/(9500-tc.c))),1) as SSS
from
    tbl_talafat_dan t1, (
       select sum(t2.t_shab+t2.t_rooz) as c
       from tbl_talafat_dan t2
       where FCode=81 AND DCode=1 AND t2.sen<=t1.sen
    ) as tc
where
    FCode = 81
    AND DCode = 1
group by
    t1.sen


I think you have a syntax issue here after t1:

from
    tbl_talafat_dan t1, (
       select sum(t2.t_shab+t2.t_rooz) as c
       from tbl_talafat_dan t2
       where FCode=81 AND DCode=1 AND t2.sen<=t1.sen
    ) as tc

It's trying to figure out what's the table to select from. You need to use either t1 or tc and join after that appropriately. Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消