目前对postgre和php的新手需要帮助获取当前日期的树木总数
*我只需要在当前日期对当前树进行计数,但似乎无法使其正常工作。
$sql = "SELECT trees.tree_type, tree_solds.transaction_id,
tree_solds.actual_height, tree_solds.selling_height,
tree_solds.sub_total,transactions.date_purchased
FROM tree_solds
LEFT JOIN trees on tree_solds.tree_id = trees.id
LEFT JOIN transactions on transactions.id = tree_solds.transaction_id
WHERE user_id = 8";
$res = pg_query($sql);
$count = pg_num_rows($res);
echo $count;
答案 0 :(得分:0)
我不知道我是否理解这是什么问题,但是因为你说"当前日期"我猜你刚才错过了过滤日期?
$sql = "SELECT trees.tree_type, tree_solds.transaction_id,
tree_solds.actual_height, tree_solds.selling_height,
tree_solds.sub_total,transactions.date_purchased
FROM tree_solds
LEFT JOIN trees on tree_solds.tree_id = trees.id
LEFT JOIN transactions on transactions.id = tree_solds.transaction_id
WHERE user_id = 8 AND transactions.date_purchased BETWEEN current_date AND current_date + INTERVAL '1 DAY'";