本帖最后由 vipstar 于 2010-03-06 18:41:15 编辑

解决方案 »

  1.   

    ---测试数据---
    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([id] int,[classid] int,[bigclassid] int,[classname] varchar(5))
    insert [tb]
    select 1,11,0,'分类1' union all
    select 2,12,11,'分类2' union all
    select 3,13,0,'分类3' union all
    select 4,14,13,'分类4' union all
    select 5,15,11,'分类5'
     
    -->查询
    select a.classname as 二级分类,b.classname as 一级分类
    from tb a,
    (select * from tb where bigclassid=0) b
    where a.bigclassid=b.classid/**
    二级分类  一级分类  
    ----- ----- 
    分类2   分类1
    分类4   分类3
    分类5   分类1(所影响的行数为 3 行)
    **/
      

  2.   

    在phpmyadmin中执行得没问题,  
    二级分类  一级分类  
    网站公告 网站信息 
    其他内容 网站信息 
    招聘专区 招聘求职 
    求职专区 招聘求职 
    兼职打工 招聘求职 
    临时雇佣 招聘求职 
    中介发布 招聘求职 
    其他用人 招聘求职 
    铺位摊位 房产专区 
    房屋求租 房产专区 
    房屋出租 房产专区 
    房屋出售 房产专区 
    房屋合租 房产专区 
    房屋求购 房产专区 
    中介信息 房产专区 
    其它信息 房产专区 
    台式电脑 电脑周边 
    笔记本 电脑周边 
    显示器 电脑周边 
    内存/CPU 电脑周边 
    主板/显卡 电脑周边 
    声卡/网卡 电脑周边 
    键盘/鼠标 电脑周边 
    硬盘 电脑周边 
    虚拟物品 电脑周边 
    电动车 车辆周边 
    摩托车 车辆周边 
    自行车 车辆周边 
    小轿车 车辆周边 
    手机 数码通讯 可为什么到网页里就出错呢。。
    SQL Error: SELECT a.classname AS 二级分类, b.classname AS 一级分类 FROM `phome_enewsclass` a, ( SELECT * FROM `phome_enewsclass` WHERE bclassid =0 )b WHERE a.bclassid = b.classid