关于SQLSever和Oracle创建视图的不同

--SQLSever

--判断是否存在--
if exists (select * from sysobjects where name = 'VW_SZYD_YTCT')
drop view VW_SZYD_YTCT
go
--创建视图
create view VW_SZYD_YTCT
as
SELECT
K.SZYDHYB_NM AS HYNM,
K.SZYDHYB_TBDWBH AS TBDWBH,
K.SZYDHYB_TBDWMC AS TBDWMC,
K.SZYDHYB_HYBH AS HYBH,
K.SZYDHYB_HYLXMC AS HYLXMC,
K.SZYDHYB_HYMC AS HYMC,
K.SZYDHYB_HYSJ AS HYSJ,
K.SZYDHYB_SBZT AS SBZT,
K.SZYDHYB_SPZT AS SPZT,
L.SZYDYTB_NM AS YTNM,
L.SZYDYTB_YTMC AS YTMC,
L.SZYDYTB_YTBM AS YTBM,
L.SZYDYTB_LXRY AS LXRY,
L.SZYDYTB_SFTG AS SFTG,
L.SZYDYTB_SFXYDB AS SFXYDB,
L.SZYDYTB_YCQK AS YCQK,
Y.SZYDYTGLSXB_SXBH AS SXBH,
Z.SZYDSXB_LXMC AS LXMC
FROM SZYDYTB L
LEFT JOIN SZYDHYB K ON K.SZYDHYB_NM=L.SZYDYTB_GLNM
LEFT JOIN SZYDYTGLSXB Y ON L.SZYDYTB_NM=Y.SZYDYTGLSXB_GLNM
LEFT JOIN SZYDSXB Z ON Z.SZYDSXB_NM=Y.SZYDYTGLSXB_SXNM

GO

--Oracle

CREATE OR REPLACE VIEW VW_SXGL_SXCX AS
SELECT
L.SXGLSXZXQK_PZNM AS PZNM,--品种内码
L.SXGLSXZXQK_PZBH AS PZBH,--品种编号
L.SXGLSXZXQK_PZMC AS PZMC,
L.SXGLSXZXQK_SSDWBH AS SSDWBH,
L.SXGLSXZXQK_SSDWMC AS SSDWMC,
L.SXGLSXZXQK_SXJGBH AS SXJGBH,
L.SXGLSXZXQK_SXJGMC AS SXJGMC,
K.SXGLSXXY_SXBZBH AS BZBH,
K.SXGLSXXY_SXBZMC AS BZMC,
SUM(L.SXGLSXZXQK_SXED) AS SXED,
SUM(L.SXGLSXZXQK_ZYED) AS ZYED,
SUM(L.SXGLSXZXQK_ZXED) AS ZXED,
SUM(L.SXGLSXZXQK_SFED) AS SFED
FROM SXGLSXZXQK L
LEFT JOIN SXGLSXXY K ON L.SXGLSXZXQK_PZBH=K.SXGLSXXY_XYBH
GROUP BY L.SXGLSXZXQK_PZNM,L.SXGLSXZXQK_PZBH,L.SXGLSXZXQK_PZMC,K.SXGLSXXY_SXBZBH,L.SXGLSXZXQK_SSDWBH,L.SXGLSXZXQK_SSDWMC,L.SXGLSXZXQK_SXJGBH,L.SXGLSXZXQK_SXJGMC,K.SXGLSXXY_SXBZMC

GO

posted @ 2020-04-29 09:16  泉城余文乐  Views(172)  Comments(0Edit  收藏  举报