数据库命令明白的回吧

来源:百度知道 编辑:UC知道 时间:2024/06/16 18:04:45
drop table ph

select distinct fcustid,fheadselfs0141 into ph from seorder

select * from wlsf2 a left join ph b on a.批次=b.fheadselfs0141 left join t_item c on b.fcustid=c.fitemid order by 物料长代码

看的懂回吧

drop table ph 的意思是删除表ph

select distinct fcustid,fheadselfs0141 into ph from seorder
的意思是从表seorder中选出fcustid和fheadselfs0141字段(不含重复值),把选出的记录放到另一个表ph中

select * from wlsf2 a left join ph b on a.批次=b.fheadselfs0141 left join t_item c on b.fcustid=c.fitemid order by 物料长代码

的意思是从表wlsf2(别名为a)中选出所有的字段,并与表ph(别名为b)作左外连接
,连接的条件是a.批次=b.fheadselfs0141 .
将连接后的结果再与表t_item(别名为c)左外连接,连接条件为b.fcustid=c.fitemid.
将以上的结果按"物料长代码"排序,默认为上升排序.

drop table ph --删除表ph

select distinct fcustid,fheadselfs0141 into ph from seorder --查询表seorder 的两个字段fcustid,fheadselfs0141并清除重复记录,用结果集新建表ph

select * from wlsf2 a left join ph b on a.批次=b.fheadselfs0141 left join t_item c on b.fcustid=c.fitemid order by 物料长代码
--查询 wlsf2 表中批次和ph表中的fheadselfs0141字段一样、ph表中fcustid字段和t_item表中fitemid的记录,以上全部为左关联,条件不成立则返回NULL值,最后按物料长代码排序

第一句 删除ph表 最好写成下面这样
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ph]')