我想在这个SQL查询中做一些数学运算。我不习惯这种语法。试图在查询中计算第3行的中位数。
- ? - =我可以在这里放一个变量吗?
- ?? - =我可以将此行变为某个变量吗?
这是我所做的代码:
if(!isset($_SESSION["username"])):
$sql_art_sum = "SELECT (SELECT count(*) FROM post WHERE user_id = ?), **-?-**
(SELECT count(*) FROM comment),
(SELECT count(*)/ **-??-** FROM comment)";
if($stmt = $mysqli->prepare($sql_art_sum)) {
$stmt->bind_param('i', $_SESSION['id']);
$stmt->execute();
$stmt->bind_result($art_sum, $comment_sum, $comment_median);
$stmt->fetch();
$stmt->close();
}
答案 0 :(得分:0)
在mysql中创建新变量时,您需要使用“AS”,例如:
SELECT x, y,
(SELECT SUM(x) - sum(y)
FROM tablename
WHERE b <= c
) as z
FROM tablename
希望这是您正在寻找的答案