[英]get two totals in one sql query
How can I get the total of hectar
and total amount
in one row rather than looping it in many rows with php and mysql?我怎样才能在一行中得到hectar
的总数和amount
,而不是用 php 和 mysql 在多行中循环?
I am using the following sql table:我正在使用以下 sql 表:
-- Database: officedb
-- 数据库: officedb
CREATE TABLE IF NOT EXISTS `agricollectcropedata` (
`kebele` varchar(50) NOT NULL,
`croptype` varchar(40) NOT NULL,
`hektar` int(40) NOT NULL,
`amount` int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `agricollectcropedata` (`kebele`, `croptype`, `hektar`, `amount`) VALUES
('b', 'wheet', 2, 12),
('a', 'wheet', 1, 5),
('a', 'wheet', 2, 6),
('a', 'wheet', 3, 12),
('a', 'wheet', 0, 0),
('a', 'wheet', 0, 0);
SELECT
sum(hektar) as hektar,
sum(amount) as amount
FROM
agricollectcropedata
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.