str_shoptop dte_toptime bm str_name
----------- ----------------------- ----------- ---------
1 2010-06-02 17:14:43.940 1 aa
5 2010-09-08 00:00:00.000 2 sd
3 2009-08-07 00:00:00.000 5 sd23
6 2009-09-06 00:00:00.000 66 dsf
5 2007-09-03 00:00:00.000 77 zhngs
4 2005-04-07 00:00:00.000 883 zhansdewo
7 2008-09-01 00:00:00.000 67 wangwu
4 2005-04-06 00:00:00.000 423 trr
7 2002-09-01 00:00:00.000 11 eee
2 2008-02-02 00:00:00.000 1212 asfdsfdsa
根据str_shoptop字段1-7级排行查询,当遇到一样的排行时,就根据时间字段dte_toptime来获取。
最后显示的数据就是1-7级,只显示7天数据。
select str_shoptop, MAX(dte_toptime) dte_toptime
from tb_a
group by str_shoptop
上面查询虽然能查到,但是下面加上bm和str_name字段后,查询就不准确了。
select str_shoptop,bm,str_name, MAX(dte_toptime) dte_toptime
from tb_a
group by str_shoptop,bm,str_name