CREATE VIEW EMAIL_CAMP AS SELECT DISTINCT(UPT.EMAIL_ID),
'N' AS FLAG FROM ITEM_MASTER_TABLE
IMT INNER JOIN ORDER_DETAIL_TABLE ODT
ON IMT.ITEM_ID = ODT.ITEM_ID
INNER JOIN ORDER_MASTER_TABLE OMT
ON ODT.ORDER_ID = OMT.ORDER_ID
INNER JOIN PAYMENT_TRANSACTION_TABLE PT
ON OMT.ORDER_ID = PT.ORDER_ID
INNER JOIN USER_PROFILE_TABLE UPT
ON OMT.USER_ID = UPT.USER_ID
WHERE PT.COUPON_CODE = 'ABCD';
我想在我的view(EMAIL_CAMP)
中添加一列,应该是自动生成的一列,任何人都可以帮我解决这个问题吗?
答案 0 :(得分:2)
您无法在视图中创建它,但每次查询时都可以添加一个,如下所示:
select @row := @row+1 as `id`, v.*
from EMAIL_CAMP v,
(select @row := 0) q
这将为每一行提供一个数字ID。