01 1 1GBS130# .00 NULL .00 .00
01 1 1GBS170# .00 NULL .00 .00
01 1 1GBS200# .00 NULL .00 .00
01 1 1GCA010# .00 NULL .00 .00
02 1 1AAA010 18.00 NULL 16.00 124.00
NULL NULL NULL NULL NULL 1.00 NULL
NULL NULL NULL NULL NULL 7.00 NULL
~~~~ ~~~~ ~~~
注意这几个值,就是这里搞不定。
01 1 1GBS170# .00 NULL .00 .00
01 1 1GBS200# .00 NULL .00 .00
01 1 1GCA010# .00 NULL .00 .00
02 1 1AAA010 18.00 NULL 16.00 124.00
NULL NULL NULL NULL NULL 1.00 NULL
NULL NULL NULL NULL NULL 7.00 NULL
~~~~ ~~~~ ~~~
注意这几个值,就是这里搞不定。
解决方案 »
- 每天定时调用接口传输5万条数据。这个需要什么技术呢?新手,求思路和关键词~~谢谢
- 只开放TCP的1433端口,SQL SERVER 不能访问
- 使用查询分析器能否访问不同数据库中的数据?
- 鏈接服務器 查询时 出现 "未能找到 OLE DB 提供程序 'sqlncli' 的注册表项。"错误
- INSERT
- 请教一个动态生成列数的SQL~谢谢
- 急!!!怎么判断表中是否含有某一列啊??
- 如何用水晶报表打印SQL Server的内容?SQL Server通过ODBC和程序连接。
- sql server 安装在winnt上连接报错:大致意思是协议只允许一个接入。不知是什么原因?
- 您好,关于在SQL SERVER上的management->agent->jobs上执行EXE文件的问题?
- 如何解决不同数据源的应用程序
- 关于存储过程
在关键字 'full' 附近有语法错误。
full outer join是不是不能连续连接两个以上的表?
select a.b,b.t,c.x from test_aa a full join test b on b.a=a.a full join test_ab c on c.a=a.a[ FROM { < table_source > } [ ,...n ] ] < table_source > ::=
table_name [ [ AS ] table_alias ] [ WITH ( < table_hint > [ ,...n ] ) ]
| view_name [ [ AS ] table_alias ] [ WITH ( < view_hint > [ ,...n ] ) ]
| rowset_function [ [ AS ] table_alias ]
| user_defined_function [ [ AS ] table_alias ]
| derived_table [ AS ] table_alias [ ( column_alias [ ,...n ] ) ]
| < joined_table >< joined_table > ::=
< table_source > < join_type > < table_source > ON < search_condition >
| < table_source > CROSS JOIN < table_source >
| [ ( ] < joined_table > [ ) ]< join_type > ::=
[ INNER | { { LEFT | RIGHT | FULL } [OUTER] } ]
[ < join_hint >
isnull(记录集,"")否则的话,空值&非空值,它会给你空值的答案,应该是这个问题
不好意思,还有一个概念性的问题帮忙说一下,我使用sum函数和group by来累加字段值,是否当group by 的时候会把数据重复累加?因为要做一个把多个表汇总成一个表的工作,没有经验,不好意思要多问几个问题。
select b.cdepartmentid as departmentid,b.ccommoditytypeid as commoditytypeid,a.ccommodityid as commodityid,a.fsaleamount as total_out_amount,a.fsalemoney as total_out_money
-- into #temp_out_stock
from sale_detail a
left join operation_head b on a.cno=b.cno and b.coperationtypeid='2'
select b.cdepartmentid as departmentid,b.ccommoditytypeid as commoditytypeid,a.ccommodityid as commodityid,a.fmoveamount as total_out_amount,a.fmovemoney as total_out_money
from move_detail a
left join operation_head b on a.cno=b.cno and b.coperationtypeid='3'
select b.cdepartmentid as departmentid,b.cincommoditytypeid as commoditytypeid,a.ccommodityid as commodityid,a.fdaamount as total_out_amount,a.fdamoney as total_out_money
from damaged_detail a
left join operation_head b on a.cno=b.cno and b.coperationtypeid='6'
-- select * from #out_stock select departmentid,commoditytypeid,commodityid,sum(total_out_amount) as total_out_amount,sum(total_out_money) as total_out_money
from #temp_out_stock
--我把上面三个查询的结果放到了#temp_out_stock里面
--但使用这个sum,和group by汇总的结果似乎把原来的数据重复累加了。
group by departmentid,commoditytypeid,commodityid
查询1的结果
01 1 1AAA010 10.00 .00
01 1 1AAA040 12.00 225.64
2的结果:
02 1 1AAA010 2.00 4.00
02 1 1AAA010 3.00 6.00
02 1 1AAA010 4.00 52.00
02 1 1AAA010 3.00 39.00
02 1 1AAA020 2.00 4.00
02 1 1AAA030 1.00 6.00
02 1 1AAA010 4.00 61.00
02 1 1AAA020 5.00 16.00
3。的结果
NULL NULL 1AAA010 2.00 .00
NULL NULL 1AAA020 4.00 .00
NULL NULL 1AAA030 1.00 .00
汇总的结果:
NULL NULL 1AAA010 2.00 .00
NULL NULL 1AAA020 4.00 .00
NULL NULL 1AAA030 1.00 .00
01 1 1AAA010 20.00 .00 (1)
01 1 1AAA040 24.00 451.28(2)
(1),(2)两处的结果好像是上面的结果重复累加了。
拜托了!
能提供点别的思路也好,我写了三天sql来实现也觉得不行。
谢谢。
union的语义很简单,就是取两个结果集的合集
union
select deparmentid,commoditytypeid,commodityid from table2
union
select deparmentid,commoditytypeid,commodityid from table3还缺什么,你看看再回复
table a:
departmentid commoditytypeid commodityid in_amount in_money
01 1 0001 22 200
01 1 0002 10 100
02 1 0001 10 100
talbe b:
departmentid commoditytypeid commodityid out_amount out_money
01 1 0001 20 300
01 1 0002 10 120
table c:
departmentid commoditytypeid commodityid stock_amount tock_money
01 1 0001 30 400
02 1 0002 40 400
01 0 0001 10 200 现在想合并为这样的表:
departmentid commoditytypeid commodityid in_amount out_amount stock_amount in_money out_money stock_money
0001 1 0001 20 20 30 200 300 400
..........
所有在这三个表中的记录都要在总表里面显示,如果别的表没有相应记录则用0代替。
departmentid,commoditytypeid,commodityid相同的能合并的就合并。在形成这三个表之前我是用sum和group把一些资料合并的,我后面再用sum,group by是为了防止重复记录存在,也就是相同的要求合并起来。sum是因为统计数量累加和。
我回去再好好想想,多谢你帮忙,有什么建议请帮我提提,我第一次处理我认为是很复杂的统计数据,有点莫不着门,呵呵,怕数据重复累加,那就失去意义了。
一:from 表1 LEFT OUTER JOIN 表2,表3
二:from 表1 LEFT OUTER JOIN 表2,LEFT OUTER JOIN 表3
三:from 表1 LEFT OUTER JOIN 表2,表2 LEFT OUTER JOIN 表3可我试了还不行!!!!!!!