把下面SQL里的SELECT单独执行,没有问题,但是用来CREATE VIEW 就报错了:
- CREATE OR REPLACE VIEW BLOG_V_ADMIN
- (ID,NICKNAME,SEX,EMAIL,PHONE,QQ,MSN,HTTP,REGISTER_TIME,
- IP,LAST_LOGIN_IP,LOGIN_TIME)
- AS
- SELECT
- A.ID,A.NICKNAME,A.SEX,A.EMAIL,A.PHONE,A.QQ,A.MSN,A.HTTP,A.REGISTER_TIME,
- B.IP AS LAST_LOGIN_IP,B.LOGIN_TIME AS LAST_LOGIN_TIME
- FROM
- BLOG_ADMIN A LEFT JOIN
- BLOG_ADMIN_LOGIN_TRACK B ON B.ADMIN = A.ID LEFT JOIN
- (SELECT ADMIN,MAX(LOGIN_TIME) AS LOGIN_TIME FROM BLOG_ADMIN_LOGIN_TRACK GROUP BY ADMIN) C ON B.ADMIN = C.ADMIN;
ERROR 1349 (HY000): View's SELECT contains a subquery in the FROM clause文章源自很文博客https://www.hinvn.com/很文博客-https://www.hinvn.com/61064.html
这是BUG吗?见:http://bugs.mysql.com/bug.php?id=16757文章源自很文博客https://www.hinvn.com/很文博客-https://www.hinvn.com/61064.html
木有办法,我只好这样改了:文章源自很文博客https://www.hinvn.com/很文博客-https://www.hinvn.com/61064.html
- CREATE OR REPLACE VIEW BLOG_V_ADMIN
- (ID,NICKNAME,SEX,EMAIL,PHONE,QQ,MSN,HTTP,REGISTER_TIME,
- LOGIN_TIME,LAST_LOGIN_IP)
- AS
- SELECT
- A.ID,A.NICKNAME,A.SEX,A.EMAIL,A.PHONE,A.QQ,A.MSN,A.HTTP,A.REGISTER_TIME,
- (SELECT LOGIN_TIME FROM BLOG_ADMIN_LOGIN_TRACK WHERE ADMIN = A.ID ORDER BY LOGIN_TIME DESC LIMIT 1) AS LAST_LOGIN_TIME,
- (SELECT INET_NTOA(IP) FROM BLOG_ADMIN_LOGIN_TRACK WHERE ADMIN = A.ID ORDER BY LOGIN_TIME DESC LIMIT 1) AS LAST_LOGIN_IP
- FROM
- BLOG_ADMIN A;
我的微信
扫一扫更精彩
大家的支持是我更新的动力!!!
评论