• mysql 视图示例


    基本操作

    建立视图

      CREATE VIEW view_test(qty,price,total) AS SELECT quantity,price,quantity*price FROM t;

    多表视图

      CREATE VIEW stu_class(id,name,glass) AS SELECT student.s_id,student.name,stu_info.glass FROM student,stu_info WHERE student.s_id = stu_info.s_id;

    查看视图

      DESCRIBE 视图名

      DESC 视图名

    查看视图基本信息

      SHOW TABLE STATUS LIKE '视图名';

    查看视图的建表信息

      SHOW CREATE VIEW 视图名

    在VIEW表中查看视图详细信息

      在mysql的information_schema数据库下的views表中存储了所有的视图定义,可以用select查看

      select * from information_schema.views;

    修改视图

      REPLACE语句

        CREATE OR REPLACE VIEW view_test AS SELECT * FROM t;

      ALTER语句

        ALTER VIEW view_test SELECT name FROM t;

    删除视图

      DROP VIEW IF EXISTS stu_glass

    建表语句示例

    /*获取系统组织结构
     *包括用户名称、用户ID、所属店面名称、所属店面ID、创建时间...
     */

    CREATE VIEW organizationTableView as select id,storename,regdate from v9_qd_account;

    /*获取当天的Cpz安装数据(按用户分组汇总)
     *包括用户ID、Cpz汇总值...
     */
    CREATE VIEW TodayCpzTableView as select storeid,storename,count(id)as total,sum(tui_num)as tui_num from v9_qd_dev where days = DATE_FORMAT(NOW(),'%Y%m%d') group by storeid;

    /*获取当月每天的Cpz安装数据(按天、用户分组汇总)
     *包括日期(天)、用户ID、Cpz汇总值、CpzApp汇总值、重复Cpz汇总值...
     */
    CREATE VIEW HistoryCurrentMonthDayView as select storeid,storename,count(id)as total,sum(tui_num)as tui_num,days from v9_qd_dev where days > DATE_FORMAT(NOW(),'%Y%m') group by storeid,days;

    /*获取每月的Cpz安装数据(按月、用户分组汇总)
     *包括日期(天)、用户ID、Cpz汇总值、CpzApp汇总值、重复Cpz汇总值...
     */
    CREATE VIEW HistoryMonthTableView as select storeid,storename,count(id)as total,sum(tui_num)as tui_num, DATE_FORMAT(FROM_UNIXTIME(installdate),'%Y%m') as months from v9_qd_dev group by storeid,months;

    /*根据输入的IMEI获取Cpz安装数据()
     *包括IMEI、账户ID、店面ID、安装时间、是否重复安装、安装app个数、手机型号
     */
    CREATE VIEW QueryCpzDatumByIMEI as select storeid,storename,verify,tui_num,sn,idfa,imei,devms,installdate from v9_qd_dev;


    //今天
    DATE_FORMAT(NOW(),'%Y%m%d');

  • 相关阅读:
    android的消息处理机制 Looper,Handler,Message
    AndroidManifest.xml 文件
    漫谈数据库索引 | 脚印 footprint(转载)
    Progress Indication while Uploading/Downloading Files using WCF(WCF制作带进度条的上传/下载)(转载)
    (转)ADO.net,Linq to SQL和Entity Framework性能实测分析
    Silverlight使用webClient上传下载
    RIA Services Staying Logged In (Ria Service持久登陆,sessioncookie,notcookie)
    OpenGL中的glLoadIdentity、glTranslatef、glRotatef原理
    Microsoft .NET 中的简化加密(转)
    Fluent API for .NET RIA Services Metadata(Reproduced)
  • 原文地址:https://www.cnblogs.com/mr-amazing/p/4613338.html
Copyright © 2020-2023  润新知