gpt4 book ai didi

php - 如果下一行不相同,则只选择行

转载 作者:行者123 更新时间:2023-11-29 03:26:32 24 4
gpt4 key购买 nike

我有一个包含歌曲代码和时间戳的表格。代码代表正在播放的歌曲,时间戳是歌曲被识别为正在播放的时间。我需要生成所有代码及其相应时间戳的列表,但只是在它们第一次被识别时。主要问题是一首歌曲可能会播放多次,唯一能表明它是歌曲的新实例的是前一行包含不同的代码。

这是我的代码(只给出每个时间码的第一个和最后一个

SELECT a.* FROM ap_results a INNER JOIN ( SELECT trackId, MAX(timeplay), timeplay FROM ap_results GROUP BY trackId ) b ON a.trackId = b.trackId AND a.timeplay > b.timeplay WHERE a.trackId <> b.trackId ORDER BY timeplay

-

╔════╦══════════╦═════════════════════╦══╗
║ id ║ trackId ║ playTime ║ ║
╠════╬══════════╬═════════════════════╬══╣
║ 1 ║ 42390-01 ║ 2016-02-01 01:00:00 ║ ║
║ 2 ║ 42390-01 ║ 2016-02-01 01:01:00 ║ ║
║ 3 ║ 42390-01 ║ 2016-02-01 01:01:25 ║ ║
║ 4 ║ 54212-04 ║ 2016-02-01 01:01:30 ║ ║
║ 5 ║ 54212-04 ║ 2016-02-01 01:01:59 ║ ║
║ 6 ║ 42390-01 ║ 2016-02-01 01:02:08 ║ ║
║ 7 ║ 12899-03 ║ 2016-02-01 01:07:02 ║ ║
║ 8 ║ 12899-03 ║ 2016-02-01 01:07:26 ║ ║
║ 9 ║ 42390-01 ║ 2016-02-01 01:08:10 ║ ║
╚════╩══════════╩═════════════════════╩══╝

我需要一个查询来显示以下内容:

42390-01 - 2016-02-01 01:00:00
54212-04 - 2016-02-01 01:01:30
42390-01 - 2016-02-01 01:02:08
12899-03 - 2016-02-01 01:07:02
42390-01 - 2016-02-01 01:08:10

最佳答案

我认为你正在寻找的东西不容易通过 sql 获得,因为它是一个程序结果..

以下是一些简短的建议(在伪代码中,因为我不知道你使用哪种服务器端语言)通过程序方法服务器端获得你的结果..

connect your db 

get all the rows in order of timeplay

set the firts rows in a var (actRow) and in an array of result rows (resultRows[])

loop over these rows starting from the second {
if the actual in loop row trackId is not the same of actRow. {
store/add this row in resultRows // for final result
and set the var for row with this value
}
}

show the resultRows

关于php - 如果下一行不相同,则只选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35346356/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com