经常遇到这样的情况,要取得所有客户的最新交易记录,读取网站所有浏览者最后一次访问时间。一个客户只读取最新的一次记录,相同,大部分的人首先想到的就是排除所有记录,相同的只取一条。用distint,但是distint只能取到一个字段的值。所以使用distint就不能读取 出所有的情况。下面是一条正确的语句:

select   *   from   表名    自定义  
  where   时间字段=(select   max(时间字段)   from   表名   where   客户ID=自定义.客户ID)

例如:

select   *   from   GradeEmployee    a  
  where   endTime=(select   max(endTime)   from   GradeEmployee   where   employeeID=a.employeeID)

 

 

ref:

http://topic.csdn.net/u/20070811/12/e2d164bf-aada-4201-981a-bba8763e4b79.html?1217829942

http://www.groovycn.cn/html/my/200806/15-37.html

http://www.phpchina.com/viewthread_51291.html

 

 

相关文章:

  • 2022-01-10
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-07-16
  • 2021-05-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案