select f_calladdr,count(f_calladdr) as i,sum(F_long) as s,name,phone
from Tab_Phone as t,users as u
where u.id=t.f_calladdr
group by f_calladdr,name,phone
f_calladdr 其实就是一个ID标识 我要统计它出现了多少次 也就i
F_long是一个数值 我要把它们根据分组后的ID标识查出再求和,也就是s
我这样写在数据库中执行的时候它会显示出所有数据,但是在我页面输出的时候它只会输出其中的一条或几条。这是为什么啊?现在就是说有没有其他的办法实现我的目的啊,我感觉好像就是count和sum排序这里有问题,但是找不出来错误所在.
出来的效果是这样的:
name phone i s
maik 138... 8 20
... ... ... ...
8 个解决方案
#1
select f_calladdr,count(f_calladdr) as i,sum(F_long) as s,name,phone
from Tab_Phone as t,users as u
where u.id=t.f_calladdr
group by f_calladdr,name,phone
刚测试完这样是好使的,但是为什么在后面加个order by sum(F_long) desc就不好使了呢
哪位高手知道啊?帮个忙!
from Tab_Phone as t,users as u
where u.id=t.f_calladdr
group by f_calladdr,name,phone
刚测试完这样是好使的,但是为什么在后面加个order by sum(F_long) desc就不好使了呢
哪位高手知道啊?帮个忙!
#2
把对应的列前缀给加上即可
#3
类似这样:
select t.f_calladdr,count(f_calladdr) as i,sum(t.F_long) as s,u.name,t.phone
from Tab_Phone as t,users as u
where u.id=t.f_calladdr
group by t.f_calladdr,u.name,t.phone
order by s desc
select t.f_calladdr,count(f_calladdr) as i,sum(t.F_long) as s,u.name,t.phone
from Tab_Phone as t,users as u
where u.id=t.f_calladdr
group by t.f_calladdr,u.name,t.phone
order by s desc
#4
select f_calladdr,count(f_calladdr) as i,sum(F_long) as s,name,phone
from Tab_Ph6 as t,users as u
where u.id=t.f_calladdr and year(F_Date)='2007'and month(F_Date)='6' and day(F_Date)='7' and F_Long>120 and UserZu between 1 and 5
group by f_calladdr,name,phone
order by sum(F_long) desc
这条SQL语句哪里有问题啊
from Tab_Ph6 as t,users as u
where u.id=t.f_calladdr and year(F_Date)='2007'and month(F_Date)='6' and day(F_Date)='7' and F_Long>120 and UserZu between 1 and 5
group by f_calladdr,name,phone
order by sum(F_long) desc
这条SQL语句哪里有问题啊
#5
select t.f_calladdr,count(f_calladdr) as i,sum(F_long) as s,u.name,u.phone
from Tab_Ph6 as t,users as u
where u.id=t.f_calladdr and year(t.F_Date)='2007'and month(t.F_Date)='6'
and day(t.F_Date)='7' and t.F_Long>120 and u.UserZu between 1 and 5
group by t.f_calladdr,u.name,u.phone
order by s desc
from Tab_Ph6 as t,users as u
where u.id=t.f_calladdr and year(t.F_Date)='2007'and month(t.F_Date)='6'
and day(t.F_Date)='7' and t.F_Long>120 and u.UserZu between 1 and 5
group by t.f_calladdr,u.name,u.phone
order by s desc
#6
试了,不行啊!郁闷!~!
有没有别的写法啊!愁人~!
有没有别的写法啊!愁人~!
#7
问题解决拉,其实很简单滴,代码如下:
select * from (
select f_calladdr,count(f_calladdr) as i,sum(F_long) as u,name,phone from tab_phone as t,users as u
where u.id=t.f_calladdr and year(F_Date)='2007'and month(F_Date)='6' and day(F_Date)='7' and F_Long>120 and UserZu between 1 and 5 group by f_calladdr,name,phone
) as tab1
order by tab1.i
select * from (
select f_calladdr,count(f_calladdr) as i,sum(F_long) as u,name,phone from tab_phone as t,users as u
where u.id=t.f_calladdr and year(F_Date)='2007'and month(F_Date)='6' and day(F_Date)='7' and F_Long>120 and UserZu between 1 and 5 group by f_calladdr,name,phone
) as tab1
order by tab1.i
#8
不过,也谢谢hxd001_810(寒冬)积极帮忙!
#1
select f_calladdr,count(f_calladdr) as i,sum(F_long) as s,name,phone
from Tab_Phone as t,users as u
where u.id=t.f_calladdr
group by f_calladdr,name,phone
刚测试完这样是好使的,但是为什么在后面加个order by sum(F_long) desc就不好使了呢
哪位高手知道啊?帮个忙!
from Tab_Phone as t,users as u
where u.id=t.f_calladdr
group by f_calladdr,name,phone
刚测试完这样是好使的,但是为什么在后面加个order by sum(F_long) desc就不好使了呢
哪位高手知道啊?帮个忙!
#2
把对应的列前缀给加上即可
#3
类似这样:
select t.f_calladdr,count(f_calladdr) as i,sum(t.F_long) as s,u.name,t.phone
from Tab_Phone as t,users as u
where u.id=t.f_calladdr
group by t.f_calladdr,u.name,t.phone
order by s desc
select t.f_calladdr,count(f_calladdr) as i,sum(t.F_long) as s,u.name,t.phone
from Tab_Phone as t,users as u
where u.id=t.f_calladdr
group by t.f_calladdr,u.name,t.phone
order by s desc
#4
select f_calladdr,count(f_calladdr) as i,sum(F_long) as s,name,phone
from Tab_Ph6 as t,users as u
where u.id=t.f_calladdr and year(F_Date)='2007'and month(F_Date)='6' and day(F_Date)='7' and F_Long>120 and UserZu between 1 and 5
group by f_calladdr,name,phone
order by sum(F_long) desc
这条SQL语句哪里有问题啊
from Tab_Ph6 as t,users as u
where u.id=t.f_calladdr and year(F_Date)='2007'and month(F_Date)='6' and day(F_Date)='7' and F_Long>120 and UserZu between 1 and 5
group by f_calladdr,name,phone
order by sum(F_long) desc
这条SQL语句哪里有问题啊
#5
select t.f_calladdr,count(f_calladdr) as i,sum(F_long) as s,u.name,u.phone
from Tab_Ph6 as t,users as u
where u.id=t.f_calladdr and year(t.F_Date)='2007'and month(t.F_Date)='6'
and day(t.F_Date)='7' and t.F_Long>120 and u.UserZu between 1 and 5
group by t.f_calladdr,u.name,u.phone
order by s desc
from Tab_Ph6 as t,users as u
where u.id=t.f_calladdr and year(t.F_Date)='2007'and month(t.F_Date)='6'
and day(t.F_Date)='7' and t.F_Long>120 and u.UserZu between 1 and 5
group by t.f_calladdr,u.name,u.phone
order by s desc
#6
试了,不行啊!郁闷!~!
有没有别的写法啊!愁人~!
有没有别的写法啊!愁人~!
#7
问题解决拉,其实很简单滴,代码如下:
select * from (
select f_calladdr,count(f_calladdr) as i,sum(F_long) as u,name,phone from tab_phone as t,users as u
where u.id=t.f_calladdr and year(F_Date)='2007'and month(F_Date)='6' and day(F_Date)='7' and F_Long>120 and UserZu between 1 and 5 group by f_calladdr,name,phone
) as tab1
order by tab1.i
select * from (
select f_calladdr,count(f_calladdr) as i,sum(F_long) as u,name,phone from tab_phone as t,users as u
where u.id=t.f_calladdr and year(F_Date)='2007'and month(F_Date)='6' and day(F_Date)='7' and F_Long>120 and UserZu between 1 and 5 group by f_calladdr,name,phone
) as tab1
order by tab1.i
#8
不过,也谢谢hxd001_810(寒冬)积极帮忙!