小编OhG*_*Why的帖子

使用MySQL以秒为单位获取ISO-8601(SCORM 2004)持续时间格式

我有一个SQL列的值像

PT2M52.37S
PT21.79S
PT53M29.68S
P
PT9S
Run Code Online (Sandbox Code Playgroud)

某些MySQL函数可以将上述格式转换为秒吗?

我已经搜索了所有内容,但没有找到与上述格式完全相同的格式。我尝试的任何日期mysql函数均无法正常工作。

有关此格式的更多信息:http : //www.ostyn.com/standards/scorm/samples/ISOTimeForSCORM.htm

PHP函数(始终为P,第一个字符)

function scorm_format_duration($duration) {
    // Fetch date/time strings.
    $stryears = get_string('years');
    $strmonths = get_string('nummonths');
    $strdays = get_string('days');
    $strhours = get_string('hours');
    $strminutes = get_string('minutes');
    $strseconds = get_string('seconds');

    if ($duration[0] == 'P') {
        // If timestamp starts with 'P' - it's a SCORM 2004 format
        // this regexp discards empty sections, takes Month/Minute ambiguity into consideration,
        // and outputs filled sections, discarding leading zeroes and any format literals …
Run Code Online (Sandbox Code Playgroud)

mysql sql datetime iso8601

5
推荐指数
1
解决办法
827
查看次数

MySQL 限制行/分组依据

我搜索了很多关于此的不同帖子,但没有找到适合我的东西。

在 GROUP BY 中使用 LIMIT 来获得每组 N 个结果?http://www.sqlines.com/mysql/how-to/get_top_n_each_group对我不起作用。

我有一个简单的 MySQL 表,其中包含以下列

id , package, user_id, date
Run Code Online (Sandbox Code Playgroud)

我想执行一个查询,我将得到

X 行 / user_id WHERE 日期 > 编号 按日期 ASC 排序

简而言之,我们想要执行Group By user_idwithLIMIT of X rows / group但要记住使用 the 的语句date column

全表示例

id , package, user_id, date
1,  full, 1 , 1447003159
2,  full, 1 , 1447003055
3,  full, 1 , 1447002022
4,  full, 1 , 1447001013
5,  full, 1 , …
Run Code Online (Sandbox Code Playgroud)

mysql

2
推荐指数
1
解决办法
4478
查看次数

标签 统计

mysql ×2

datetime ×1

iso8601 ×1

sql ×1