为了创建包含行数的 2 个表的视图,我已经这样做了(2 个视图)
第一个视图
CREATE VIEW view_tmp
AS
SELECT id_user,
COUNT(*) totCount
FROM t1
WHERE data < DATE_ADD( curdate( ) , INTERVAL 16 DAY )
AND alert = 1 GROUP BY id_user
第二视图
CREATE VIEW view_final
AS
SELECT t1.id_user,
t2.email,
COALESCE(s.totCount,0) totCount
FROM t1
INNER JOIN t2 ON t2.userid = t1.id_user
LEFT JOIN view_tmp s ON s.id_user = t2.userid
WHERE data < DATE_ADD( curdate( ) , INTERVAL 16 DAY )
AND alert = 1 GROUP BY id_user
我想使用单个语句“create”而不使用临时视图来创建“view_final”,可以吗?谢谢。