I have 2 tables
1st: order
columns: id
, date
, price
2nd: paypal
columns: id
, posted_date
, amount
the columns date
and posted_date
contains the full date & time details; day/month/year hrs:minute:seconds
I need to get the data by grouping by the day from the both tables
order
.date
(day by day)order
table for each dayprice
records from order
table for each dayamount
records from the another table paypal
table for the same daysI can't imagine if I should use join, union, union all, or just merge by comma
答案 0 :(得分:0)
SELECT DATE(O.`dater`) AS Dates,
COUNT(O.orders) AS Order_count,
SUM(O.price) as Total_Price,
(SELECT SUM(amount) FROM paypal WHERE DATE(O.`dater`)=`posted_date`) AS Total_Amount
FROM orders O
GROUP BY DATE(O.`dater`)
Note:(I have used column dater
instead of column date
)
Hope this helps.
答案 1 :(得分:0)
这个为我工作:)
SELECT DATE(O.`date`) AS Dates,
COUNT(O.order) AS Order_count,
SUM(O.price) as Total_Price,
(SELECT SUM(amount) FROM paypal WHERE DATE(O.`date`)=`posted_date`) AS Total_Amount
FROM order O
GROUP BY DATE(O.`date`)