SQLSERVER
if exists(select * from sysobjects where id=OBJECT_ID(N‘VW_SZYD_YTCT‘) and objectproperty(id,N‘IsView‘)=1)
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,
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;
原文地址:https://www.cnblogs.com/997icu/p/12673937.html