Skip to content

Instantly share code, notes, and snippets.

@digitalhitler
Created September 13, 2017 21:47
Show Gist options
  • Save digitalhitler/6ff8724b6a6e223c9ae4001f5fdf20dd to your computer and use it in GitHub Desktop.
Save digitalhitler/6ff8724b6a6e223c9ae4001f5fdf20dd to your computer and use it in GitHub Desktop.
Stats queries for BBA
SELECT
DATE(`A`.`PublishedAt`) AS `Date`,
COUNT(`A`.`ID`) AS `TotalEntries`,
`A`.`BoardID` AS `Board`,
(SELECT `Label` AS `BoardLabel` FROM `Boards` `BR` WHERE `ID` = `A`.`BoardID` LIMIT 1) AS `BL`
FROM `Ads` `A`
WHERE
`A`.`PublishedAt`
BETWEEN
TIMESTAMP(
SUBDATE(
CURRENT_DATE(), INTERVAL 31 DAY
)
)
AND
CURRENT_TIMESTAMP()-- BETWEEN '2012-01-01 00:00:00' AND '2012-01-31 23:59:59'
GROUP BY `Date`, `BoardID`
ORDER BY `Date` DESC
-- SELECT
--
-- TIMESTAMPDIFF(DAY,`PublishedAt`, CURRENT_TIMESTAMP()) AS "DaysAgo",
--
-- DATE(`PublishedAt`) AS `Date`,
--
-- `Title` AS `Title`
-- FROM `A`
--
-- WHERE `DaysAgo` < 31
-- #GROUP BY `Date`
-- #HAVING
SELECT
SUM(DISTINCT `B`.`TotalEntries`) AS `OverallEntries`,
`B`.`Date`
FROM
(SELECT
DATE(`A`.`PublishedAt`) AS `Date`,
COUNT(`A`.`ID`) AS `TotalEntries`,
`A`.`BoardID` AS `Board`
FROM `Ads` `A`
WHERE
`A`.`PublishedAt`
BETWEEN
TIMESTAMP(
SUBDATE(
CURRENT_DATE(), INTERVAL 31 DAY
)
)
AND
CURRENT_TIMESTAMP()-- BETWEEN '2012-01-01 00:00:00' AND '2012-01-31 23:59:59'
GROUP BY `Date`, `BoardID`
ORDER BY `Date` DESC) AS `B`
GROUP BY `B`.`Date`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment