视图创建唯一行约束,并且拼接复合主键
CREATE OR REPLACE VIEW VW_SXGL_SXPZZXQKCX AS
SELECT
//复合主键
CONCAT(CONCAT(L.SXGLSXZXQK_PZBH,L.SXGLSXZXQK_SSDWBH),CONCAT(L.SXGLSXZXQK_SXJGBH,K.SXGLSXXY_SXBZBH)) as NM,
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_XYBH=K.SXGLSXXY_XYBH
GROUP BY L.SXGLSXZXQK_PZBH,L.SXGLSXZXQK_PZMC,K.SXGLSXXY_SXBZBH,L.SXGLSXZXQK_SSDWBH,L.SXGLSXZXQK_SSDWMC,L.SXGLSXZXQK_SXJGBH,L.SXGLSXZXQK_SXJGMC,K.SXGLSXXY_SXBZMC;
//唯一性约束
alter view VW_SXGL_SXPZZXQKCX
add constraint PK_VW_SXGL_SXPZZXQKCX primary key (NM)
disable novalidate;