Answer the question
In order to leave comments, you need to log in
What is the error in this SQL query?
When executing a request in PHPMyAdmin, a hang occurs.
PHPMyAdmin doesn't give any messages, it just shows a "Loading" message, you have to kill the process.
SELECT download_count.id,
date_format(start_date, '%D %b %Y') as 'start',
date_format(max(wp1.tracking_date),'%M') as 'mouth',
date_format(max(wp1.tracking_date),'%D %b %Y') as 'last',
COUNT(wp1.download_id) as 'last_mouth_count',
COUNT(wp2.download_id) as 'today_count'
FROM download_count
LEFT JOIN download_info as wp1 on download_count.id=wp1.download_id AND NOT ISNULL(wp1.tracking_date) AND date_format(wp1.tracking_date, '%Y-%m')=date_format(now(), '%Y-%m')
LEFT JOIN download_info as wp2 on download_count.id=wp2.download_id AND NOT ISNULL(wp2.tracking_date) AND date_format(wp2.tracking_date, '%Y-%m-%d')=date_format(now(), '%Y-%m-%d')
WHERE download_count.id=wp2.download_id AND download_count.id=wp1.download_id
CREATE TABLE `download_count` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(150) NOT NULL,
`url` varchar(150) NOT NULL,
`full` int(1) NOT NULL DEFAULT '0',
`plugin_id` int(4) unsigned NOT NULL,
`start_date` datetime NOT NULL,
`used_date` datetime DEFAULT NULL,
`count` bigint(20) NOT NULL DEFAULT '0',
`cat_id` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=87 DEFAULT CHARSET=utf8;
CREATE TABLE `download_info` (
`tracking_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`download_id` bigint(20) unsigned NOT NULL,
`tracking_referer` varchar(355) DEFAULT NULL,
`tracking_date` datetime NOT NULL,
`user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`user_refferal` varchar(350) DEFAULT NULL,
`additional_info` varchar(32) DEFAULT NULL,
`version_id` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`tracking_id`),
KEY `download_id` (`download_id`)
) ENGINE=InnoDB AUTO_INCREMENT=50243 DEFAULT CHARSET=utf8;
Answer the question
In order to leave comments, you need to log in
What is the error in this SQL query?
WHERE download_count.id=wp2.download_id AND download_count.id=wp1.download_id
why are join conditions duplicated here?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question