在SQL查询中使用按功能分组 [英] using of group by function in sql query

查看:159
本文介绍了在SQL查询中使用按功能分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好
我在msaccess 2003中遇到了小问题,我正在编写查询
通过使用Group类起作用
它的示例代码是

hi good morning
i had a littel problem with my msaccess 2003 , i am writing the query
by using the Group class is working
and its sample code is

"select b.custrefno,SUM(b.paidamount) as paidamount from paym b,addcust a  where  b.custrefno=a.custrefno GROUP BY b.custrefno";



完美地工作

在这里它以一种完美的方式工作,因为我需要一些额外的列,以便我添加了诸如name,email,mobile之类的Columns名称;
这样我就可以像这样更改查询



working prefectly

here it is working in the perfect way , by i need some extra columns so that i had added the Columns names as like name , email,mobile;
so that i had change the query just like this

"select a.email,a.name,a.mobile,b.custrefno,SUM(b.paidamount) as paidamount from paym b,addcust a  where  b.custrefno=a.custrefno GROUP BY b.custrefno";



我也试过这样,但是



i had also tryied like this but

"select email,name,mobile,b.custrefno,SUM(b.paidamount) as paidamount from paym b,addcust a  where  b.custrefno=a.custrefno GROUP BY b.custrefno";



但是最后两个不能完美执行,它产生了类似
的错误


Error: You tried to execute a query that does not include the specified expression ''email'' as part of an aggregate function.

我要去哪里了,哪里出了问题了,有人可以帮我吗

从本质上讲,我的要求是通过分组,我需要获取特定记录的名称和移动电话号码.



but last two are not working executing prefectly , it created the error like



Error: You tried to execute a query that does not include the specified expression ''email'' as part of an aggregate function.

where i am going wrong, and what''s the wrong is , can any body help me

basycally my requirement is by grouping i need to get the Name and mobile number of that particular record

推荐答案

将不在汇总函数中的列放入GROUP BY中条款.例如这样.

Put the columns that are not inside an aggregate function in the GROUP BY clause. Like this for example.

"select email,name,mobile,b.custrefno,SUM(b.paidamount) as paidamount from paym b,addcust a  where  b.custrefno=a.custrefno GROUP BY b.custrefno,email,name,mobile";


尝试使用"a.email,a.name,a.mobile"让它知道数据源在哪里...

您不需要那(早,我还在喝第一杯咖啡)
而是在GROUP BY子句中列出电子邮件,姓名和移动电话

[edit]糟糕-OriginalGriff [/edit]
Try using "a.email, a.name, a.mobile" to let it know where the datasource is...

You don''t need that (it''s early, I''m still on my first cup of coffee)
Instead, list the email, name and mobile in the GROUP BY clause

[edit]Oops - OriginalGriff[/edit]


这篇关于在SQL查询中使用按功能分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆