这个SQL中报一个错误,怎么修改正确呢?先谢谢帮忙的人!

wangnaisheng 2012-09-28 09:51:34
select

dg.chr_deliver_date as chr_back_ymd,--日期

'发货' as State_One,--摘要(状态)

dd.chr_product_name as chr_product_name,--产品型号(产品名)

dd.chr_bill_count as chr_bill_count,--数量

dd.chr_bill_price as chr_bill_price,--单价

dd.chr_serial_no as chr_fapiao_no,--发票号

dd.billmoney as chr_bill_money,--发货金额

'' as chr_pay_cash,--回款

'' as chr_back_ymd1--欠款(需统计加减)

from tt_deliver_goods_tbl as dg--发货表

left join (
select tm_product_tbl.chr_product_name,dd1.chr_dingdan_no,dd1.chr_bill_count,dd1.chr_bill_price,
dd1.chr_serial_no,COALESCE(dd1.chr_bill_money,0) as billmoney

from tt_dingdan_detail_tbl as dd1

left join tm_product_tbl

on tm_product_tbl.chr_product_id=dd1.chr_product_id

)as dd -----订单详细表

on dg.chr_dingdan_no =dd.chr_dingdan_no

order by chr_back_ymd

-----
union all
------
select

tc.chr_done_date as chr_back_ymd,--日期

'上单结转' as State_One,--摘要(状态)

'' as chr_product_name,--产品型号(产品名)

'' as chr_bill_count,--数量

'' as chr_bill_price,--单价

'' as chr_fapiao_no,--发票号

'' as chr_bill_money,--发货金额

'' as chr_pay_cash,--回款

tc.chr_cash_before as chr_back_ymd--欠款(需统计加减)

from tt_customer_bank_tbl as tc --客户账户表

where '2012-10-01' > chr_done_date

and int_nub_no in (

select max(int_nub_no) from tt_customer_bank_tbl

group by chr_customer_id

) order by int_nub_no desc

...全文
243 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangnaisheng 2012-09-28
  • 打赏
  • 举报
回复
好的 解决了! 谢谢各位哈!!!
wangnaisheng 2012-09-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

你google搜索下

关键字

order by union

里面有解决方法
[/Quote]

是不能用在union里面!

但是如果哪个数量是整型的话 我用'' 这样不给赋值行吗?
wangnaisheng 2012-09-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

你是sql 2000吧?
Order by不能直接在union子句中使用
[/Quote]

不是 我用的是postgre 数据库的哦!
孟子E章 2012-09-28
  • 打赏
  • 举报
回复
你google搜索下

关键字

order by union

里面有解决方法
孟子E章 2012-09-28
  • 打赏
  • 举报
回复
你是sql 2000吧?
Order by不能直接在union子句中使用
快溜 2012-09-28
  • 打赏
  • 举报
回复
去掉order by
wangnaisheng 2012-09-28
  • 打赏
  • 举报
回复
ERROR: syntax error at or near "union"
LINE 40: union all
^

********** 错误 **********

ERROR: syntax error at or near "union"
SQL 状态: 42601
字符:836

这是哪个错误!该什么解决呢?

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧