樓上的方法不行,會出錯. Server: Msg 8118, Level 16, State 1, Line 1 Column 'es_sampl_job.Job_Code' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.
distinct是指相同的记录只取一条。 你的记录是没有相同的呀。没有错误! job_code不可能为唯一的,除非你不要job_date字段,或者改用group语句: SELECT max(job_date) from es_sampl_job group by job_code
SELECT job_code,job_date from es_sampl_job where job_code in (select distinct job_code from es_sampl_job ) 大概就是这样
SELECT distinct job_code,max(job_date) from es_sampl_job Group By job_code--------------------------------------------------------- Montaque==Digitalboy==Houyongfeng==Monkey
试试 SELECT DISTINCT JOB_CODE,CONVERT(CHAR(10),JOB_DATE,120) FROM ES_SAMP1_JOB
Server: Msg 8118, Level 16, State 1, Line 1
Column 'es_sampl_job.Job_Code' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.
你的记录是没有相同的呀。没有错误!
job_code不可能为唯一的,除非你不要job_date字段,或者改用group语句:
SELECT max(job_date) from es_sampl_job group by job_code
大概就是这样
Group By job_code---------------------------------------------------------
Montaque==Digitalboy==Houyongfeng==Monkey
FROM ES_SAMP1_JOB