從下面的表格中,我怎麼可能得到這樣的數據: 我的sql知識僅限於select和其他基本的東西。如何做一個sql來從這樣的表中獲取數據?
Heading 1 Eg: Kitchenware
Heading 2 Eg: Knives
Heading 3 Eg: Butter Knives
Item: Cut em all
Item: Cull em all
Item: Smear em all
Heading 3 Eg: Meat Knives
Item: Cut em meat
Item: Cull em meat
Item: Smear em meat
1級和2級是標題,不能放置物品。 3級可以容納物品。等級4是項目。有可能做到以上幾點。有時候,3級可能會級別後1
"id" "name" "description" "level" "parent" "country" "maxLevel"
"1" "Kitchenware" "Kitchenware description" "1" "0" "US" "0"
"2" "Knives" "All our knives" "2" "1" "US" "0"
"3" "Butter Knives" "All Butter Knives" "3" "2" "US" "0"
"4" "Cut em all" "Cut em all" "4" "3" "US" "0"
"5" "Cull em all" "Cull em all" "4" "3" "US" "0"
"6" "Smear em all" "Smear em all" "4" "3" "US" "0"
"7" "Meat Knives" "All Meat Knives" "3" "2" "US" "0"
"8" "Cut em meat" "Cut em meat" "4" "7" "US" "0"
"9" "Cull em meat" "Cull em meat" "4" "7" "US" "0"
"10" "Smear em meat" "Smear em meat" "4" "7" "US" "0"
表創建
CREATE TABLE `products` (
`id` INT(10) NULL AUTO_INCREMENT,
`name` VARCHAR(50) NULL DEFAULT NULL,
`description` VARCHAR(240) NULL DEFAULT NULL,
`level` TINYINT(1) NULL DEFAULT '0',
`parent` INT(10) NULL DEFAULT '0',
`country` VARCHAR(2) NULL DEFAULT NULL,
`maxLevel` INT(1) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM;
表數據
INSERT IGNORE INTO `products` (`id`, `name`, `description`, `type`, `parent`, `country`, `maxLevel`) VALUES
(1, 'Kitchenware', 'Kitchenware description', 1, 0, 'US', 0),
(2, 'Knives', 'All our knives', 2, 1, 'US', 0),
(3, 'Butter Knives', 'All Butter Knives', 3, 2, 'US', 0),
(4, 'Cut em all', 'Cut em all', 4, 3, 'US', 0),
(5, 'Cull em all', 'Cull em all', 4, 3, 'US', 0),
(6, 'Smear em all', 'Smear em all', 4, 3, 'US', 0),
(7, 'Meat Knives', 'All Meat Knives', 3, 2, 'US', 0),
(8, 'Cut em meat', 'Cut em meat', 4, 7, 'US', 0),
(9, 'Cull em meat', 'Cull em meat', 4, 7, 'US', 0),
(10, 'Smear em meat', 'Smear em meat', 4, 7, 'US', 0);
見http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ – Barmar 2013-05-05 14:42:56
@Barmar我一直用這個,自上午上面的文章,然後貼在這裏:) – Norman 2013-05-05 14:48:35