一种数据库模式
2015-12-08 09:28
453 查看
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_service` AS select sum((case when (`b`.`itemname` = 'Limited client access') then `b`.`item` end)) AS `limited`, ifnull(sum((case when (`b`.`itemname` = 'saveclips') then `b`.`item` end)),'0') AS `saveclips`, sum((case when (`b`.`itemname` = 'Service time') then `b`.`item` end)) AS `servicetime`, sum((case when (`b`.`itemname` = 'price') then `b`.`item` end)) AS `price`, sum((case when (`b`.`itemname` = 'DVR days') then `b`.`item` end)) AS `dvrday`, (case when (sum((case when ((`b`.`itemname` = 'type') and (`b`.`item` = 'standard')) then 0 when ((`b`.`itemname` = 'type') and (`b`.`item` = 'premium')) then 1 end)) = 1) then 'premium' when (sum((case when ((`b`.`itemname` = 'type') and (`b`.`item` = 'standard')) then 0 when ((`b`.`itemname` = 'type') and (`b`.`item` = 'premium')) then 1 end)) = 0) then 'standard' when (sum((case when ((`b`.`itemname` = 'type') and (`b`.`item` = '1 day')) then 0 when ((`b`.`itemname` = 'type') and (`b`.`item` = '11 days')) then 1 when ((`b`.`itemname` = 'type') and (`b`.`item` = '21 days')) then 2 end)) = 0) then '1 day' when (sum((case when ((`b`.`itemname` = 'type') and (`b`.`item` = '1 day')) then 0 when ((`b`.`itemname` = 'type') and (`b`.`item` = '11 days')) then 1 when ((`b`.`itemname` = 'type') and (`b`.`item` = '21 days')) then 2 end)) = 1) then '11 days' when (sum((case when ((`b`.`itemname` = 'type') and (`b`.`item` = '1 day')) then 0 when ((`b`.`itemname` = 'type') and (`b`.`item` = '11 days')) then 1 when ((`b`.`itemname` = 'type') and (`b`.`item` = '21 days')) then 2 end)) = 2) then '21 days' when (sum((case when ((`b`.`itemname` = 'type') and (`b`.`item` = '1 day')) then 0 when ((`b`.`itemname` = 'type') and (`b`.`item` = '7 days')) then 1 when ((`b`.`itemname` = 'type') and (`b`.`item` = '30 days')) then 2 end)) = 1) then '7 days' when (sum((case when ((`b`.`itemname` = 'type') and (`b`.`item` = '1 day')) then 0 when ((`b`.`itemname` = 'type') and (`b`.`item` = '7 days')) then 1 when ((`b`.`itemname` = 'type') and (`b`.`item` = '30 days')) then 2 end)) = 2) then '30 days' when (sum((case when ((`b`.`itemname` = 'type') and (`b`.`item` = '1 day')) then 0 when ((`b`.`itemname` = 'type') and (`b`.`item` = '7 days')) then 1 when ((`b`.`itemname` = 'type') and (`b`.`item` = '3 days')) then 2 end)) = 2) then '3 days' else 'trial' end) AS `servicetype`, (case when (sum((case when ((`b`.`itemname` = 'currency') and (`b`.`item` = 'USD')) then 1 end)) = 1) then 'USD' else 'RMB' end) AS `currency`, sum((case when (`b`.`itemname` = 'order') then `b`.`item` end)) AS `order`, `a`.`serviceid` AS `serviceid`, `a`.`servicename` AS `servicename` from ((`o_service` `a` join `o_item` `b`) join `o_service_item` `c`) where ((`a`.`serviceid` = `c`.`serviceid`) and (`b`.`itemid` = `c`.`itemid`) and (`a`.`status` = '0')) group by `a`.`serviceid`
相关文章推荐
- MyBatis学习 之 二、SQL语句映射文件(1)resultMap
- 数据库优化策略
- MySQL主备复制数据不一致的情况
- iOS开发中使用SQL语句操作数据库的基本用法指南
- MyBatis构建sql时动态传入表名以及字段名
- oracle之报错:ORA-00054: 资源正忙,要求指定 NOWAIT
- MyBatis学习 之 四、动态SQL语句
- MyBatis学习 之 二、SQL语句映射文件(2)增删改查、参数、缓存
- 二、SQL语句映射文件(1)resultMap
- Mysql条件判断语法
- mysql 优化(1)
- 10gocm->session5->数据库管理实验->GC资源管理器的资源消耗组介绍
- sql where 1=1 0=1 的妙用
- MySQL复合分区
- memcached下载地址 php 5.3~5.6
- 对jsp+servlet+mysql中乱码问题的部分总结
- 【数据库】数据库的bak格式备份与还原
- navicat 连接sqlserver提示要安装 sql server native client
- Mysql #1406 Data too long 错误
- NOSQL数据库简介