select t1.分类,t1.商品名称,table.库存,t1.更新时间
from (
select 分类,商品名称,max(更新时间) 更新时间 from table
group by 分类,商品名称
) t1
inner join table on t1.分类=table.分类 and t1.商品名称=table.商品名称 and t1.更新时间
=table.更新时间
关于SQL最大值查询语句的记录
SELECT
bsnum,
STATE AS FILE_STATE
FROM
FILE_RECORD r
WHERE
STATE =(
SELECT
MAX(STATE)
FROM
FILE_RECORD
WHERE
bsnum = r.bsnum
);
小技巧:有时需要测试sql语法但又觉得创建表麻烦,可以使用创建一个临时表,如下:
select id, count(t.id) from
(
select 1 as id, 2 as age, 'F' as sex from dual union
select 2 as id, 2 as age, 'M' as sex from dual union
select 3 as id, 3 as age, 'F' as sex from dual union
select 4 as id, 4 as age, 'M' as sex from dual
)t