一种数据库模式

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`

你可能感兴趣的:(一种数据库模式)