赞
踩
1、MySQL创建表
CREATE TABLE `category` (
`categoryid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT "主题id",
`pid` INT(10) NOT NULL COMMENT "父id",
`categoryName` VARCHAR(50) NOT NULL COMMENT '主题名字',
PRIMARY KEY (`categoryid`)
)ENGINE=INNODB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8
2.MySQL向表中插入数据
INSERT INTO `category` (`categoryid`, `pid`, `categoryName`)
VALUES("2","1","信息技术"),
("3", "1","软件开发"),
("4", "3", "数据库"),
("5", "1", "美术设计"),
("6", "3", "web开发"),
("7", "5", "ps技术"),
("8", "2", "办公信息");
3、查询父子信息
SELECT a.`categoryName` AS "父栏目",b.`categoryName` AS "子栏目"
FROM`category` AS a, `category` AS b
WHERE a.`categoryid` = b.`pid`
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。