sql 查询父级菜单是否有子菜单 怎么写?

来源:百度知道 编辑:UC知道 时间:2024/06/19 00:30:08
表如下:
id name parentid
1 1 0
2 2 0
3 3 0
4 4 1
5 5 1

现在希望查询出全部的父级信息(0代表最高级信息)。
现在获得的结果是

id name 子信息条数
1 1 2
2 2 0
3 3 0

小弟实力很弱,希望谁能帮帮小弟我。。。

var width = $(window).width()-80;
var height = $(window).height()-120;
stView_layout = $('#stView_layout').layout({
width: width,
height: height
});
station_view = $('#stationView').window({
title: '测站导航',
left:50,
top:80,
width: width,
modal: false,
shadow: false,
closed: true,
height: height,
onResize:function(w,h){
if(stView_treegrid){
stView_treegrid.treegrid({
width:w-20,
height:h-260
});
}
}
});

select t.id,t.name,(select count(tt.id) from test tt where tt.parentid=1) count from test t where t.id=1 union select t.id,t.name,(select count(tt.id) from test tt where tt.parentid=2) count from test t where t.id=2 union select t.id