SELECT CYear AS Date,
(SELECT COUNT(*) FROM COMPANIES WHERE (YEAR(reg_date) = CY.CYear)) AS opened_count,
(SELECT COUNT(*) FROM COMPANIES WHERE (YEAR(terminate_date) = CY.CYear)) AS terminate_count
FROM (
SELECT YEAR(C1.reg_date) AS CYear
FROM COMPANIES AS C1
WHERE (NOT (C1.reg_date IS NULL))
UNION
SELECT YEAR(C2.terminate_date) AS CYear
FROM COMPANIES AS C2
WHERE (NOT (C2.terminate_date IS NULL))) AS CY
DELETE FROM wp_mailpoet_subscriber_segment
FROM wp_mailpoet_subscriber_segment
INNER JOIN wp_mailpoet_subscribers
ON wp_mailpoet_subscribers.id = wp_mailpoet_subscriber_segment.subscriber_id
WHERE wp_mailpoet_subscribers.link_token = '66301e'
AND wp_mailpoet_subscriber_segment.segment_id = 1
GROUP BY events.id
CREATE TABLE `author` (
`id` INT(10) NOT NULL,
`name` VARCHAR(200) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
`fam` VARCHAR(200) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
`birthday` DATE NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `books` (
`id` INT(10),
`id_author` INT(10) NULL DEFAULT NULL,
`book` VARCHAR(500) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
PRIMARY KEY (`id`),
INDEX `id_author` (`id_author`)
);
INSERT INTO `author` (`id`, `name`, `fam`, `birthday`) VALUES (1, 'Николай Николаевич', 'Носов', '2008-11-23');
INSERT INTO `author` (`id`, `name`, `fam`, `birthday`) VALUES (2, 'Артур Конан', 'Дойль', '1859-05-22');
INSERT INTO `books` (`id`, `id_author`, `book`) VALUES (1, 1, 'Незнайка учится');
INSERT INTO `books` (`id`, `id_author`, `book`) VALUES (2, 1, 'Незнайка-путешественник');
INSERT INTO `books` (`id`, `id_author`, `book`) VALUES (3, 1, 'Винтик, Шпунтик и пылесос');
SELECT a.id, a.name, a.fam, GROUP_CONCAT(DISTINCT b.book ORDER BY b.book ASC SEPARATOR ', ') AS books
FROM `author` a
LEFT JOIN `books` b ON a.id=b.id_author
GROUP BY a.id;
SELECT Concat(calendar.name, " ", calendar.year) as name, ifnull(date.value1,0) AS value
FROM (SELECT DISTINCT date.year, month.id, month.name FROM date, month) AS calendar
LEFT JOIN date
ON date.year = calendar.year AND date.month_id = calendar.id
ORDER BY calendar.year, calendar.id LIMIT 6 OFFSET 18
ограничиваясь текущим месяцем … последние 6
SELECT Concat(calendar.name, " ", calendar.year) as name, ifnull(date.value1,0) AS value
FROM (SELECT DISTINCT date.year, month.id, month.name FROM date, month) AS calendar
LEFT JOIN date
ON date.year = calendar.year AND date.month_id = calendar.id
WHERE CONCAT(calendar.year, '-', LPAD( calendar.id, 2, '0'))
> LEFT(DATE_SUB(NOW(), INTERVAL 6 MONTH), 7)
ORDER BY calendar.year, calendar.id LIMIT 6
CREATE TABLE "12345"( Value char(10));
Под рукой развернутой базы ну никак нетRextester.