Want to mysql select a generated ZhaoBiaoLv TAB, include field: month, departments, total purchases, bid purchases, ZhaoBiaoLv, among them, the bidding purchases is purchasing way as the "tender" purchases data, ZhaoBiaoLv is bidding purchase amount present a combination,
How do I write the select command,,
CodePudding user response:
E.g.
in the SELECT, the department
, the SUM (purchases) AS those from
, CONCAT (CAST (SUM (CASE WHEN purchasing way='tender' THEN purchases ELSE 0 END)/SUM (purchases) * 100.0 AS a DECIMAL (18, 2)), '%') AS ZhaoBiaoLv
The FROM table1
In GROUP BY
, the department;