这里我就简单描述下使用,使用的是ruby
的查询语法,不过大体相同,就是使用CONCAT
关键字
ruby 语法
msg_doctor_name = agent.doctors.where(go_public_sea_day:3).joins(:orders).select("CONCAT(doctors.name,'(',count(orders.id),'单)') as msg").map(&:msg) || nil
mysql语法
SELECT CONCAT(doctors.name,'(',count(orders.id),'单)') as msg FROM `doctors` INNER JOIN `orders` ON `orders`.`doctor_id` = `doctors`.`id` INNER JOIN `agent_doctors` ON `doctors`.`id` = `agent_doctors`.`doctor_id` WHERE `agent_doctors`.`agent_id` = 350 AND `doctors`.`go_public_sea_day` = 3