2016-09-11 111 views
0

我正在使用MySQL並出現sql錯誤。我需要有不同的列datetime和每一個不同的日期時間,我想表明的最大impact_idMYSQL錯誤1064,如何解決它?

選擇MAX(impact_id),從新聞 不同datetim 其中impact_id不是null datetim不爲空
按datetim 爲了通過datetim ASC

我收到錯誤

SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'distinct datetim from news where impact_id is not null and 

datetim不爲空」

CREATE TABLE `news` (
    `datetim` DATETIME NULL DEFAULT NULL, 
    `symbol` VARCHAR(50) NULL DEFAULT NULL, 
    `impact` VARCHAR(50) NULL DEFAULT NULL, 
    `_id` MEDIUMINT(9) NOT NULL AUTO_INCREMENT, 
    `impact_id` INT(11) NULL DEFAULT NULL, 
    PRIMARY KEY (`_id`) 
) 
COLLATE='utf8_general_ci' 
ENGINE=InnoDB 
AUTO_INCREMENT=3072 
; 

回答

0

select distinct max(impact_id),datetim from news where impact_id is not null and datetim is not null group by datetim order by datetim asc