select jhdb.jhdh from jhdb 改为 select tmpalias.jhdh from jhdb tmpalias试验一下!前缀jhdb没有定义一个alias名称! 所以可以直接这么引用 select jhdh from jhdb 不用alias.
谢谢,问题解决, 但我不明这条语句的意思 jhdb A 以前不知道有这种写法
select A.jhdh,A.gysbh,A.yfmoney,A.ytmoney,B.money from jhdb A (select jhdh,sum(dj*sl) as money from jhmxb group by jhdh) B where (A.jhdh=B.jhdh) and (A.yfmoney+A.ytmoney=B.money)// 还是出错了 Server: Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'select'. Server: Msg 170, Level 15, State 1, Line 2 Line 2: Incorrect syntax near ')'.
在这里A表示别名了 --------- 一般来说在用到多个表的联系查询时才用它, 当然有时候列也用别名,比如: select cname as 中文名 from userinfo
在jhdb a 后面应该有个逗号 或者 try thisselect a.jhdh,a.gysbh,a.yfmoney,a.ytmoney, sum(b.dj*b.sl) as money from jhdb a, jhmxb b where a.jhdh=b.jhdh and a.yfmoney+a.ytmoney=money group by b.jhdb 呵呵,不知道对不对
看来你对SQL的联合查询非常不熟悉。 建议先去看看帮助。 ------- 你的错误很明显 select A.jhdh,A.gysbh,A.yfmoney,A.ytmoney,B.money from jhdb A,--这里少了一个逗号 (select jhdh,sum(dj*sl) as money from jhmxb group by jhdh) B where (A.jhdh=B.jhdh) and (A.yfmoney+A.ytmoney=B.money)
select tmpalias.jhdh from jhdb tmpalias试验一下!前缀jhdb没有定义一个alias名称!
所以可以直接这么引用
select jhdh from jhdb
不用alias.
(select jhdh,sum(dj*sl) as money from jhmxb group by jhdh) B
where (A.jhdh=B.jhdh) and (A.yfmoney+A.ytmoney=B.money)// 还是出错了
Server: Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'select'.
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near ')'.
---------
一般来说在用到多个表的联系查询时才用它,
当然有时候列也用别名,比如:
select cname as 中文名 from userinfo
或者
try thisselect a.jhdh,a.gysbh,a.yfmoney,a.ytmoney, sum(b.dj*b.sl) as money from jhdb a, jhmxb b
where a.jhdh=b.jhdh and a.yfmoney+a.ytmoney=money
group by b.jhdb
呵呵,不知道对不对
建议先去看看帮助。
-------
你的错误很明显
select A.jhdh,A.gysbh,A.yfmoney,A.ytmoney,B.money from jhdb A,--这里少了一个逗号
(select jhdh,sum(dj*sl) as money from jhmxb group by jhdh) B
where (A.jhdh=B.jhdh) and (A.yfmoney+A.ytmoney=B.money)
相当于jhdb as A