我正在使用MySQL并出现sql错误。我需要为日期时间和每个不同的日期时间设置不同的列,我想显示max impact_id
选择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 :(得分: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