我原来的语句是
select id,Title,Date,condition,appraise from consult_enterprise where company ='xxx公司' order by Date desc
从每一列取该数据按照公司名字调取,
我做了一个追问的链接,因此想在主页上只显示相同title最早提问的数据
比如说:
title date ……
777 17:50 (延伸的扩展回答)
777 17:00 (延伸的扩展回答)
777 13:00 (主要问题)
但是我现在在主datalist中,不想显示相同的问题,只需要显示主要问题
我在上面sql语句的基础上如何更改啊
select id,Title,Date,condition,appraise from consult_enterprise where company ='xxx公司'and Title in (select distinct * from consult_enterprise ) order by Date desc
这个好像有点问题 子查询只能为一个
求更正
------解决方案--------------------
select id,Title,Date,condition,appraise from consult_enterprise a
where company ='xxx公司' and
not exists
(select 1 from consult_enterprise where title=a.title and a.date<date)
------解决方案--------------------
select
id,Title,Date,condition,appraise
from consult_enterprise As a
Where Not Exists(Select 1 from consult_enterprise As x
Where x.Title=a.Title
And x.Date<=a.Date
) --- 相同Title下,不存在比查詢的時間更早(就是等於查詢最早時間)
where company ='xxx公司' order by Date desc