WINFROM里根据T_Purchasing表的订单号,得到以下数据:
T_Id T_PartsNumber T_Model T_Quantity T_segment1 T_segment2 T_count
4 H-23-02-010 贴片电阻-10R-0603 2 null null null
T_segment4 T_segment5 T_count1 T_segment7 T_segment8 T_count2
null null null null null null
select T_Purchasing.T_Id,T_Purchasing.T_PartsNumber,T_Purchasing.T_Model,T_Purchasing.T_Quantity,T_segment1,
T_segment2,T_count,T_segment4,T_segment5,,T_count1,T_segment7,T_segment8,,T_count2 from T_Purchasing where T_Purchasing.T_DjNumber='20101021001'//查的语句
还有张T_SupplierrosterShop表查出 T_price最小的前3位
T_specifications T_price T_job
H-23-02-010 0.004 上海银航电子有限公司
H-23-02-010 0.0048 上海中欣电子有限公司
H-23-02-010 0.0048 上海荣利明电子有限公司
select top 3 T_SupplierrosterShop.T_specifications,T_SupplierrosterShop.T_price,T_SupplierrosterShop.T_job from T_SupplierrosterShop where
T_SupplierrosterShop.T_specifications='H-23-02-010' order by T_price//查的语句现在我想要得到这样的数据//T_count,1,2=T_Quantity*T_segment1 ,4,7
T_PartsNumber T_Model T_Quantity T_segment1 T_segment2 T_count
H-23-02-010 贴片电阻-10R-0603 2 0.004 上海银航电子有限公司 0.004*2
T_segment4 T_segment5 T_count1 T_segment7 T_segment8 T_count2
0.0048 上海中欣电子有限公司 0.0048*2 0.0048 上海荣利明电子有限公司 0.0048*2
急啊怎么显示出来啊
T_Id T_PartsNumber T_Model T_Quantity T_segment1 T_segment2 T_count
4 H-23-02-010 贴片电阻-10R-0603 2 null null null
T_segment4 T_segment5 T_count1 T_segment7 T_segment8 T_count2
null null null null null null
select T_Purchasing.T_Id,T_Purchasing.T_PartsNumber,T_Purchasing.T_Model,T_Purchasing.T_Quantity,T_segment1,
T_segment2,T_count,T_segment4,T_segment5,,T_count1,T_segment7,T_segment8,,T_count2 from T_Purchasing where T_Purchasing.T_DjNumber='20101021001'//查的语句
还有张T_SupplierrosterShop表查出 T_price最小的前3位
T_specifications T_price T_job
H-23-02-010 0.004 上海银航电子有限公司
H-23-02-010 0.0048 上海中欣电子有限公司
H-23-02-010 0.0048 上海荣利明电子有限公司
select top 3 T_SupplierrosterShop.T_specifications,T_SupplierrosterShop.T_price,T_SupplierrosterShop.T_job from T_SupplierrosterShop where
T_SupplierrosterShop.T_specifications='H-23-02-010' order by T_price//查的语句现在我想要得到这样的数据//T_count,1,2=T_Quantity*T_segment1 ,4,7
T_PartsNumber T_Model T_Quantity T_segment1 T_segment2 T_count
H-23-02-010 贴片电阻-10R-0603 2 0.004 上海银航电子有限公司 0.004*2
T_segment4 T_segment5 T_count1 T_segment7 T_segment8 T_count2
0.0048 上海中欣电子有限公司 0.0048*2 0.0048 上海荣利明电子有限公司 0.0048*2
急啊怎么显示出来啊
(
T_Id int identity(1,1) primary key,
T_DjNumber varchar(100),--单据编号
T_ItemNumber varchar(100),--所属项目编号
T_ShopNumber varchar(100),--产品编号
T_Objective varchar(500),--采购目的
T_Number varchar(50),--编号
T_Name varchar(500) ,--货品名称
T_Quantity int,--数量
T_PartsNumber varchar(100),--零件编号
T_Model varchar(500),--所属类型
T_DepotName varchar(100),--库位名
T_Re varchar(1000),--备注
T_Principal varchar(20),--制表人
T_date datetime,--制表日期
T_people varchar(20),--审批人
T_Choose int default 0,--审批是否通过
T_uid int,
T_count varchar(100),--合计
T_segment1 varchar(100),
T_segment2 varchar(100),
T_segment3 varchar(100),
T_count1 varchar(100),--合计
T_segment4 varchar(100),
T_segment5 varchar(100),
T_segment6 varchar(100),
T_count2 varchar(100),--合计
T_segment7 varchar(100),
T_segment8 varchar(100),
T_segment9 varchar(100),
T_lastchoose varchar(100)
)
create table T_SupplierrosterShop--供应商报价比较表
(
T_id int identity(1,1) primary key,
T_specifications varchar(50),--物料号
T_num varchar(100),--封装
T_name varchar(100),--物料名
T_model varchar(100),--型号
T_job varchar(200),--供应商名
T_price varchar(50),--报价
T_count int,--数量
T_fkfs varchar(50),--付款方式
T_data varchar(50),--到货期
T_sum varchar(50),--合计价格
T_SupplierrosterNameid int --通讯录外键
)
2张表
http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
T_Purchasing.T_PartsNumber,T_Purchasing.T_Model,T_Purchasing.T_Quantity,
T_segment1,T_segment2,T_count,
T_segment4,T_segment5,T_count1,
T_segment7,T_segment8,T_count2
from T_Purchasing where T_Purchasing.T_DjNumber='20101021001'//查的语句---结果
4
H-23-02-010 贴片电阻-10R-0603 2
null null null
null null null
null null null select top 3 T_specifications,T_price,T_job
from T_SupplierrosterShop
where T_specifications='H-23-02-010' order by T_price//查的语句--还有张T_SupplierrosterShop表查出 T_price最小的前3位T_specifications T_price T_job
H-23-02-010 0.004 上海银航电子有限公司
H-23-02-010 0.0048 上海中欣电子有限公司
H-23-02-010 0.0048 上海荣利明电子有限公司想要结果
当然是一行,即把三行,合并到一行的其它列中
T_specifications T_price T_job
H-23-02-010 0.004 上海银航电子有限公司
H-23-02-010 0.0048 上海中欣电子有限公司
H-23-02-010 0.0048 上海荣利明电子有限公司H-23-02-010 贴片电阻-10R-0603 2
0.004 上海银航电子有限公司 0.004*2
0.0048 上海中欣电子有限公司 0.0048*2
0.0048 上海荣利明电子有限公司 0.0048*2
;with cte as
(
select * from
(select T_specifications,T_price,T_job,id=row_number() over(order by T_price desc)
from T_SupplierrosterShop
where T_specifications='H-23-02-010' ) T
where id<=3 order by t_price desc
)select T_Id
,T_PartsNumber,T_Model,T_Quantity,
T_segment1=t1.T_price,T_segment2=t1.t_job,T_count=T_Quantity*t1.t_price,
T_segment4=t2.T_price,T_segment5==t2.t_job,T_count1=T_Quantity*t2.t_price,
T_segment7==t3.T_price,T_segment8==t3.t_job,T_count2=T_Quantity*t3.t_price
from T_Purchasing ,cte t1 ,cte,t2,cte t3
where t1.id=1 and t2.id=2 and t3.id=3 and T_Purchasing.T_DjNumber='20101021001'
select T_Id
,T_PartsNumber,T_Model,T_Quantity,
T_segment1=t1.T_price,T_segment2=t1.t_job,T_count=T_Quantity*t1.t_price,
T_segment4=t2.T_price,T_segment5=t2.t_job,T_count1=T_Quantity*t2.t_price,
T_segment7=t3.T_price,T_segment8=t3.t_job,T_count2=T_Quantity*t3.t_price
from T_Purchasing ,cte t1 ,cte,t2,cte t3
where t1.id=1 and t2.id=2 and t3.id=3 and T_Purchasing.T_DjNumber='20101021001'
H-23-02-010 贴片电阻-10R-0603 2 0.004 上海银航电子有限公司 0.004*2
T_segment4 T_segment5 T_count1 T_segment7 T_segment8 T_count2//列
0.0048 上海中欣电子有限公司 0.0048*2 0.0048 上海荣利明电子有限公司 0.0048*2
不知道会乱么