您的位置:首页 > 数据库

SQL语句:一种连接本表2个查询结果的复杂sql语句、一种查找一列有重复值的语句

2008-04-11 16:19 746 查看
--SQL语句:一种连接本表2个查询结果的复杂sql语句、一种查找一列有重复值的语句
--数据库test的imagestore表包含以下字段:
--autoId,stationId,cardIndex,directionIndex,captureTime,uploadTime,roadImage

USE test
GO

SELECT * FROM imagestore
WHERE capturetime = (SELECT MAX(capturetime) FROM imagestore WHERE stationid = 1002 and directionindex =1)
and stationID = 1002 and directionindex = 1
UNION ALL
SELECT * FROM imagestore
WHERE capturetime = (SELECT MAX(capturetime) FROM imagestore WHERE stationid = 1002 and directionindex =3)
and stationID = 1002 and directionindex = 3
GO

SELECT * FROM imagestore where stationId in (SELECT stationId FROM imagestore GROUP BY stationId HAVING(COUNT(*) > 1))
GO
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐