mysql 创建视图

CREATE
 VIEW v_image_org_user_album AS--创建视图并命名v_image_org_user_album
    SELECT --先开from中表的命名
        a.id AS imgid,--将a表中的id命名为新的表(视图)中的imgid字段,剩下的都一样,就是将之前的字段重新命名到新视图表中的字段
        a.comment AS comment,
        a.createtime AS createtime,
        a.path AS path,
        b.name AS authorname,
        b.orgcode AS userorgcode,
        c.name AS orgname,
        e.name AS album
    FROM
      t_image a ,--image表命名为a
      left join t_user b on a.bid=b.bid,--user表命名为b
      left join t_organization c on b.cid=c.cid,--organzation表命名为c
    //  t_album_image d,--album_image表命名为d
    //  t_album e--album表命名为e
    WHERE
        a.useracc = b.account
            AND b.orgcode = c.orgcode
            AND a.id = d.imageid
            AND d.albumid = e.id

https://dev.mysql.com/doc/refman/5.6/en/create-view.html

posted @ 2018-03-25 14:58  让双脚&去腾空  阅读(447)  评论(0编辑  收藏  举报