这语句应该怎么写啊

caoyang0299 2011-06-24 01:48:27
select A.*,B.*FROM
(select '2:3酸99%' as 产品名称,
t1.fdecimal17 as 计划销售额
from t_BOS200002351entry t1 ,t_BOS200002351 t
where t.fid=t1.fid and t.finteger=2000) A,
(select
sum(fconsignamount) as 实际销售额
from ICStockBill i,ICStockBillentry i1
where i.finterid=i1.finterid and i1.fitemid=154
and i.ftrantype=21
and year(i.fdate)=2011 group by i1.fitemid) B

这是一条记录,还有多条记录需要union,
例如2:3酸98% i1.fitemid=153
这语句应该怎么写?
谢谢
...全文
79 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
cd731107 2011-06-24
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 lxpbs8851 的回复:]
楼主 直接把你涉及到的表结构 和你所需要的结果 弄出来
[/Quote]
说的对,否则别人是帮不上忙的
oO寒枫Oo 2011-06-24
  • 打赏
  • 举报
回复
楼主 直接把你涉及到的表结构 和你所需要的结果 弄出来
caoyang0299 2011-06-24
  • 打赏
  • 举报
回复
是这样的
cd731107 2011-06-24
  • 打赏
  • 举报
回复
ICStockBillentry这个表有fitemid,还有没有它对应的产品名称
caoyang0299 2011-06-24
  • 打赏
  • 举报
回复
怎么写,哪位大侠帮帮忙
oO寒枫Oo 2011-06-24
  • 打赏
  • 举报
回复
A B没有关系干嘛算笛卡尔积
caoyang0299 2011-06-24
  • 打赏
  • 举报
回复
select A.*,B.*FROM
(select '2:3酸99%' as 产品名称,
t1.fdecimal17 as 计划销售额
from t_BOS200002351entry t1 ,t_BOS200002351 t
where t.fid=t1.fid and t.finteger=2000) A,
(select
sum(fconsignamount) as 实际销售额
from ICStockBill i,ICStockBillentry i1
where i.finterid=i1.finterid and i1.fitemid=154
and i.ftrantype=21
and year(i.fdate)=2011 group by i1.fitemid) B

union all
select A.*,B.*FROM
(select '2:3酸98%' as 产品名称,
t1.fdecimal17 as 计划销售额
from t_BOS200002351entry t1 ,t_BOS200002351 t
where t.fid=t1.fid and t.finteger=2000) A,
(select
sum(fconsignamount) as 实际销售额
from ICStockBill i,ICStockBillentry i1
where i.finterid=i1.finterid and i1.fitemid=153
and i.ftrantype=21
and year(i.fdate)=2011 group by i1.fitemid) B
结果是这样的,怎么优化一下
caoyang0299 2011-06-24
  • 打赏
  • 举报
回复
计划跟销售没有关联
SQL77 2011-06-24
  • 打赏
  • 举报
回复
这是一条记录,还有多条记录需要union,
例如2:3酸98% i1.fitemid=153

楼主这两个没有建表关联起来??
caoyang0299 2011-06-24
  • 打赏
  • 举报
回复
计划销售额,实际销售额
2:3 酸99%, 44 55
色酚 33 23

名字是自己取的(根据itemid的不通),计划销售额是一个表的数据,实际是另一个表的数据

语句杂写
loworth 2011-06-24
  • 打赏
  • 举报
回复
不懂 回复不能太短

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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