1
我想製作一個報告系統,我需要爲每個日期顯示報告 。顯示關於特定日期的數據?
這些是selected_items 我的表架構這是stock_list
我在前端,後端和java使用PHP來顯示 數據。我嘗試了幾個查詢來獲得所需的輸出,但是我遠遠得不到它。這些是我使用的一些查詢。
SELECT
COALESCE(stock_list.date, selected_items.date) AS date,
SUM(stock_list.qty) AS StockSum,
SUM(stock_list.weight) AS Stockweight,
COUNT(selected_items.barcode) AS BilledItems,
SUM(selected_items.weight) AS Billedweight
FROM stock_list join selected_items
ON stock_list.date = selected_items.date
GROUP BY COALESCE(stock_list.date, selected_items.date)
ORDER BY COALESCE(stock_list.date, selected_items.date);
這給了我第一個五列,但輸出給了我錯誤的價值觀。 然後我也試過聯盟。
SELECT SUM(qty) AS StockSum, SUM(weight) AS Stockweight
FROM `stock_list`
WHERE DATE LIKE '08-Jan-2016'
UNION SELECT COUNT(barcode) AS BilledItems, SUM(weight) AS Billedweight
FROM `selected_items`
WHERE DATE LIKE '08-Jan-2016'
UNION SELECT SUM(qty) AS TotalStock, SUM(weight) AS TotalWeight
FROM `stock_list`;
在這裏我得到了正確的值四列,但問題是>結果顯示在兩列的時候,我想它是在4列。 任何人都可以引導我,我已經認爲它的Java部分,但我不擅長PHP和MySQL。 謝謝
謝謝@LordAnomander你能幫助解決方案嗎 – AndroidNewBee
你會共享表格模式嗎? – AnkiiG
是啊@AnkiiG請檢查更新的問題。謝謝 – AndroidNewBee