gpt4 book ai didi

php - 如何组合这些 mysql 查询

转载 作者:行者123 更新时间:2023-11-29 02:18:26 25 4
gpt4 key购买 nike

查询 1

$query = "SELECT stock_issue.*,stock_item.item_name 
FROM stock_issue,stock_item
WHERE stock_issue.idate>=$from
AND stock_issue.idate<=$to
AND stock_issue.item_id=stock_item.ID
ORDER BY stock_issue.idate DESC";

查询 2

$query = "SELECT stock_purchase.*,stock_item.item_name
FROM stock_purchase,stock_item
WHERE stock_purchase.pdate>=$from
AND stock_purchase.pdate<=$to
AND stock_purchase.itemid=stock_item.ID
ORDER BY stock_purchase.pdate DESC";

请帮助我...

最佳答案

尝试使用此代码

SELECT stock_issue.*,stock_item.item_name 
FROM stock_issue,stock_item
WHERE stock_issue.idate>='$from'
AND stock_issue.idate<='$to'
AND stock_issue.item_id=stock_item.ID
ORDER BY stock_issue.idate DESC

UNION

SELECT stock_purchase.*,stock_item.item_name
FROM stock_purchase,stock_item
WHERE stock_purchase.pdate>='$from'
AND stock_purchase.pdate<='$to'
AND stock_purchase.itemid=stock_item.ID
ORDER BY stock_purchase.pdate DESC

就是这样

$sql=$query1.'UNION'.$query2;

关于php - 如何组合这些 mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35620759/

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