开发者

get the longest hierarchy

In the DataBase i Stored the Some information(represented in the Attached ScreenShot)

get the longest hierarchy

what is the best way开发者_Go百科 to get the longest hierarchy id?

in the attached pic the longest hierarchy is 128 ,because it has the least number of 0's values in it's fields(t_definition_types_id_(1-4))

Thank You


another way is like :

SELECT id,
 (IF(t_definition_types_id_1>0, 1, 0) + 
  IF(t_definition_types_id_2>0, 1, 0) +
  IF(t_definition_types_id_3>0, 1, 0) +
  IF(t_definition_types_id_4>0, 1, 0) 
) 
AS level 
FROM mytable ORDER BY level DESC


Try this:

SELECT id
FROM myTable 
ORDER BY 
    t_definition_types_id_4 DESC, 
    t_definition_types_id_3 DESC, 
    t_definition_types_id_2 DESC, 
    t_definition_types_id_1 DESC
LIMIT 1;

The question's a tad foggy but I think that's what you're trying to do. Correct me if I'm wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜