我的观点给出了合理正确的答案:
DELIMITER $$
DROP VIEW IF EXISTS `test`.`new_temp`$$
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `new_temp` AS
SELECT `temp`.`pcount` AS `ind_type`,SUM(`temp`.`pcount`) AS `Index_val` FROM `temp` UNION ALL
SELECT `temp`.`ncount` AS `sum`,SUM(`temp`.`ncount`) AS `ncount` FROM `temp` $$
DELIMITER ;
输出:
ind_type Index_val
----------------------
2 23
2 34
我希望它给出这样的输出:
New_temp
ind_type Index_val
-------------------------------
pcount 23
ncount 34
问题在于我编写的代码。我尝试了不同的方式,但我没有得到它。任何想法?