Mulugeta  Endeshaw
Mulugeta Endeshaw

Reputation: 1

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?

I am using the following sql table:

-- Database: 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);

Upvotes: 0

Views: 37

Answers (1)

J. Kim
J. Kim

Reputation: 39

SELECT 
  sum(hektar) as hektar, 
  sum(amount) as amount 
FROM 
  agricollectcropedata 

Upvotes: 2

Related Questions