在mysql的一张表中,我想根据Id查询两个字段的总数相加了在根据相加有的大小排序? 150

,谢谢!急需在mysql的一张表中?请问该如何写SQL语句呢..,我想根据Id查询两个字段的总数相加了在根据相加有的大小排序
留言'文章ID'
where article='select id;评论',a+b as zongshu from table
order by a+b

是这样的;
b是select count(*) from table where typeid=',a是slect count(*) from table where typeid='
发布于2010-03-09 14:50 最佳答案
elect articleid;评论',') group by articleid order by zongshu desc;;留言',count(*) as zongshu from table where typeid in ('

其他回答

为相加后的结果取个别名,再按别名排序就行了.
示例:
select
(COL1+COL2) SUMCOL
from TBL_TEST
order by SUMCOL
波迪 | 发布于2010-03-09 11:08
评论
create table abc(
id1 int,
id2 int
)
insert into abc(id1,id2)values(1,2)
insert into abc(id1,id2)values(2,3)
insert into abc(id1,id2)values(3,4)
insert into abc(id1,id2)values(1,3)

select *from abc order by (id1+id2)
qsc800528 | 发布于2010-03-09 11:11
评论
两个字段的总数相加
啥意思?
字段A+B后,在对A+B的值排序?

要分组:
select article,sum(a)+sum(b) from table
group by article
order by sum(a)+sum(b)
需要确认的是a,b是不是table表中的字段呢?
要你命三千之赵 | 发布于2010-03-09 12:31
评论
select id,a+b as zongshu from table
order by a+b

select a.id,b.p1+c.p2 as zongshu from table a
inner join (slect 文章ID,count(*) p1 from table where typeid='评论'
group by 文章ID) b on a.文章ID=b.文章ID
inner join (select 文章ID,count(*) p2 from table where typeid='留言'
group by 文章ID) c on a.文章ID=c.文章ID
where 文章ID=你的条件
order by b.p1+c.p2
jonahjeff | 发布于2010-03-09 13:26
评论
SELECT `para1` + `para2`
FROM `tablename`
ORDER BY `para1` + `para2_id` DESC
where id in () or id between 1 and 10000
馹④絔° | 发布于2010-03-09 11:10
评论
收起 其他4条回答

为您推荐: