数据库查询某一字段值的id排序,用在查询另一个字段的值上
我用下面的命令取得了字段key里views值的降序排列,如图SELECTid,key,valueFROM'my'WHEREkey='views'orderbyvalueD...
我用下面的命令取得了字段key里views值的降序排列,如图
SELECT id,key,value FROM 'my' WHERE key = 'views' order by value DESC LIMIT 0 , 30
现在我想用上面id的排序,取得字段key里的logo值,下图是直接查询的结果
注:编程语言php 展开
SELECT id,key,value FROM 'my' WHERE key = 'views' order by value DESC LIMIT 0 , 30
现在我想用上面id的排序,取得字段key里的logo值,下图是直接查询的结果
注:编程语言php 展开
3个回答
展开全部
假设xxx 是你的 第二个表:
SELECT t2.id,t2.key,t2.value,t1.value FROM 'my' t1,xxx t2 WHERE t1.key = 'views'
and t2.key = 'logo' and t1.id = t2.id
order by t1.value DESC LIMIT 0 , 30
SELECT t2.id,t2.key,t2.value,t1.value FROM 'my' t1,xxx t2 WHERE t1.key = 'views'
and t2.key = 'logo' and t1.id = t2.id
order by t1.value DESC LIMIT 0 , 30
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SELECT id,key,value FROM 'my'
where kdy='logo' and id in( select id from 'my'
WHERE key = 'views' )order by id DESC
where kdy='logo' and id in( select id from 'my'
WHERE key = 'views' )order by id DESC
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询