CREATE OR REPLACE VIEW vBluesealProductPublishedRateListView AS
SELECT
  count(distinct `shp`.`productVariantId`) as count,
  month(`releaseDate`) = 0 as rdCount

    concat(monthname(`releaseDate`), ' ', substr(year(`releaseDate`), 3, 4)) as `time`,
    `s`.`id` as `shopId`,
    `s`.`title` as `shopName`,
    (SELECT count(*) as c FROM `ShopHasProduct` as `ssub` WHERE `ssub`.`shopId` = `shp`.`shopId` AND `ssub`.releaseDate <= LAST_DAY(`shp`.`releaseDate`)) as published,
    `s`.`minReleasedProducts` as stima,
    `s`.`minReleasedProducts` / 100 as percent,
    round(`s`.`minReleasedProducts` / 100 * count(`shp`.`productVariantId`), 1) as rate
  FROM
  `ShopHasProduct` as `shp` JOIN `Shop` as `s` ON `s`.`id` = `shp`.`shopId`
  WHERE `shp`.`releaseDate` IS NOT NULL
  GROUP BY `year`, `month`, `s`.`id` #ORDER BY `year` desc, `month` desc, `shp`.`shopId` asc
