比较 SQL 查询中的两个 UNIX 时间戳
Compare two UNIX timestamps inside a SQL query
我希望获取具有 hour_status = 1
且位于当前行之后的下一行(已获取并显示)。我希望在 UNIX 时间戳之后对它们进行排序。我已经在谷歌搜索和搜索尝试不同的东西,但 none 到目前为止已经奏效了。那么如何在 SQL 查询中执行此操作?
想要的结果是:
sent_date < (PREVIOUS ROWS sent_date)
这是我已有的代码:
$sql_two = "SELECT FROM_UNIXTIME(sent_date) FROM user_hours WHERE hour_id = ?";
$stmt_two = $mysqli->prepare($sql_two) or die ("Feil i database<br>" . $sql_two . "<br><b>Feilmelding:</b> " . $mysqli->error);
$stmt_two->bind_param('i',$hourId);
$stmt_two->execute() or die("noe gikk galt");
$stmt_two->bind_result($db_prev_sent_date);
$stmt_two->fetch();
$sql = "SELECT hour_id FROM user_hours WHERE hour_status = 1 AND FROM_UNIXTIME(sent_date) < ? ORDER BY FROM_UNIXTIME(sent_date) desc LIMIT 1";
$stmt = $mysqli->prepare($sql) or die ("Feil i database<br>" . $sql . "<br><b>Feilmelding:</b> " . $mysqli->error);
$stmt->bind_param('i',$db_prev_sent_date);
$stmt->execute() or die("noe gikk galt");
$stmt->bind_result($db_hour_id_next);
$stmt->fetch();
由于您只需要显示下一行并单独进行更新,因此您的解决方案非常适合您所遇到的情况。
我希望获取具有 hour_status = 1
且位于当前行之后的下一行(已获取并显示)。我希望在 UNIX 时间戳之后对它们进行排序。我已经在谷歌搜索和搜索尝试不同的东西,但 none 到目前为止已经奏效了。那么如何在 SQL 查询中执行此操作?
想要的结果是:
sent_date < (PREVIOUS ROWS sent_date)
这是我已有的代码:
$sql_two = "SELECT FROM_UNIXTIME(sent_date) FROM user_hours WHERE hour_id = ?";
$stmt_two = $mysqli->prepare($sql_two) or die ("Feil i database<br>" . $sql_two . "<br><b>Feilmelding:</b> " . $mysqli->error);
$stmt_two->bind_param('i',$hourId);
$stmt_two->execute() or die("noe gikk galt");
$stmt_two->bind_result($db_prev_sent_date);
$stmt_two->fetch();
$sql = "SELECT hour_id FROM user_hours WHERE hour_status = 1 AND FROM_UNIXTIME(sent_date) < ? ORDER BY FROM_UNIXTIME(sent_date) desc LIMIT 1";
$stmt = $mysqli->prepare($sql) or die ("Feil i database<br>" . $sql . "<br><b>Feilmelding:</b> " . $mysqli->error);
$stmt->bind_param('i',$db_prev_sent_date);
$stmt->execute() or die("noe gikk galt");
$stmt->bind_result($db_hour_id_next);
$stmt->fetch();
由于您只需要显示下一行并单独进行更新,因此您的解决方案非常适合您所遇到的情况。