我想使用SQL Group By子句将输出作为不同表的组,我有不同的表但内部结构相同。我的表名称是具有相同数据的位置名称
答案 0 :(得分:0)
这是一种方法:
SELECT t1.TimeStamp, t2.State, t1.OtherData
FROM Table1 t1
inner join Table2 t2
on t1.SpecialNumber = t2.SpecialNumber
inner join (SELECT MAX(time stamp) maxts, state
FROM table1 inner join table2
ON table1.specialnumber = table2.specialnumber
GROUP BY state) t3
on t2.State = t3.State and t1.TimeStamp = t3.maxts