Home > database >  Mysql query total purchases and tender amount?
Mysql query total purchases and tender amount?

Time:09-19

Have a list (table1), include field: month, department, purchases, purchase way,

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;
  • Related