I have 2 tables like below:
a. table_order_detail
---------------------------------------------|
artnr | price | transactiondate | deptnr |
---------------------------------------------|
1 | 1000 | 2020-01-23 01:30:11 | 1 |
1 | 1500 | 2020-01-24 23:43:24 | 1 |
3 | 2000 | 2020-01-24 12:31:52 | 1 |
b. table_article
----------------------|
artnr | cost | deptnr |
----------------------|
1 | 500 | 1 |
2 | 700 | 1 |
3 | 1500 | 1 |
I want to show data with GROUP BY
table_order_detail.transactiondate but with DATE only (like this question ).
My SQL query is like below but not show data:
$sqldatanetrevenue = mysqli_query($con, "SELECT DATE(table_order_detail.transactiondate) AS orderdate, table_order_detail.price, table_article.cost, table_order_detail.orderstatusitem
FROM table_order_detail INNER JOIN table_article
ON table_order_detail.artnr = table_article.artnr
WHERE ((table_order_detail.deptnr='$departmentnr')
AND CAST(table_order_detail.transactiondate AS DATE) BETWEEN '$fromdate' AND '$todate')
GROUP BY orderdate
");
But this query is work without GROUP BY
:
$sqldatanetrevenue = mysqli_query($con, "SELECT DATE(table_order_detail.transactiondate) AS orderdate, table_order_detail.price, table_article.cost, table_order_detail.orderstatusitem
FROM table_order_detail INNER JOIN table_article
ON table_order_detail.artnr = table_article.artnr
WHERE ((table_order_detail.deptnr='$departmentnr')
AND CAST(table_order_detail.transactiondate AS DATE) BETWEEN '$fromdate' AND '$todate')
");
Assume $fromdate value is 2020-01-01 and $todate value is 2020-01-31. The second query show the data. But I want to group by date, but I don't know exactly what went wrong.
Expected result:
-------------------------------|
artnr | price | transactiondate|
-------------------------------|
1 | 1000 | 2020-01-23 |
1 | 3500 | 2020-01-24 |