Public feed #380507

Someone

public text v1 · immutable
Raw Edit
·published 2007-03-04 03:20 UTC
rendered paste body
CREATE TABLE `buildings`
(`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`parent_id` INT NOT NULL,
`accommodation` INT NOT NULL,
`name` VARCHAR(100) NOT NULL)

INSERT INTO `buildings` (`id` , `parent_id` , `accommodation` , `name`)
  VALUES (NULL, '-1', '10', 'Main Building');
INSERT INTO `buildings` (`id` , `parent_id` , `accommodation` , `name`)
  VALUES (NULL, LAST_INSERT_ID(), '4', 'Auxiliary Building');


is there an sql query that will return the following results?

+----+-----------+--------------------+---------------+---------------------+
| id | parent_id | name               | accommodation | total_accommodation |
+----+-----------+--------------------+---------------+---------------------+
|  1 |        -1 | Main Building      |            10 |                  14 | 
|  2 |         1 | Auxiliary Building |             4 |                   4 | 
+----+-----------+--------------------+---------------+---------------------+