![](/img/trans.png)
[英]get records from two different tables based on their respective datetime fields - mysql
[英]how to get different fields from different records from same table based on some condition in mysql
Date Unit-1 Unit-2
1/1/2017 250 300
1/2/2017 150 225
1/3/2017 320 null
1/4/2017 null 200
1/5/2017 100 200
請幫我看看如何在mysql中獲得結果
請嘗試以下查詢:
SELECT
`date`,
TRIM(BOTH ',' FROM (GROUP_CONCAT(CASE WHEN unit='Unit-1' THEN amount ELSE '' END),',','') AS `Unit-1`,
TRIM(BOTH ',' FROM (GROUP_CONCAT(CASE WHEN unit='Unit-2' THEN amount ELSE '' END),',','') AS `Unit-2`
FROM myTable GROUP BY `date`;
這是你想要的圖像中顯示的記錄嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.