sql

Posted CrossPython

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql相关的知识,希望对你有一定的参考价值。

id,zhiliangdengjiid,type1,wuliaoid,danhao,lingliao,type2


select * from (select a.id,a.zhiliangdengjiid,a.type1,b.wuliaoid,b.danhao,b.lingliao,b.type2 FROM (
SELECT id,zhiliangdengjiid,\'FG\' as type1 FROM [ZJHJDB].[dbo].[HJ_bomdanhead] a WHERE a.ID=(SELECT TOP 1 ID from [ZJHJDB].[dbo].[HJ_bomdanhead] WHERE a.zhiliangdengjiid=zhiliangdengjiid ORDER BY status asc) AND LEN(a.zhiliangdengjiid)>1
) as a
INNER JOIN (
SELECT [id],[wuliaoid],[danhao],[lingliao],(CASE WHEN lingliao=-1 THEN \'P\' ELSE \'M\' END) AS type2 FROM [ZJHJDB].[dbo].[HJ_bomdan2]
) as b ON a.id=b.id) as aa
union all
select * from (
SELECT c.id,b.zhiliangdengjiid,b.type1,c.wuliaoid,c.danhao,c.lingliao,c.type2 FROM
(SELECT [id],[zhiliangdengjiid],\'M\' as type1 FROM [ZJHJDB].[dbo].[HJ_peifangbiao] AS a WHERE a.ID=
(SELECT TOP 1 ID FROM [ZJHJDB].[dbo].[HJ_peifangbiao] WHERE a.zhiliangdengjiid=zhiliangdengjiid order by status asc) AND len(a.zhiliangdengjiid)>1
) AS b
INNER JOIN (
SELECT id,wuliaoid,danhao,lingliao,(CASE WHEN lingliao=-1 then \'P\' else \'M\' end) AS type2 FROM [ZJHJDB].[dbo].[HJ_peifangbiao2] WHERE id not in (SELECT id FROM [ZJHJDB].[dbo].[HJ_peifangbiao2] WHERE LEN(wuliaoid)=0)
) AS c on b.ID=c.ID
) as bb

以上是关于sql的主要内容,如果未能解决你的问题,请参考以下文章

sql [sql技巧]一些sql技巧#sql

sql 2008 r2 在sql 2008上兼容么

SQL基础

有大神知道,sql server 中如何批量执行sql语句吗?

pl sql developer怎么执行sql

pl sql developer怎么执行sql