复杂分组查询 [英] Complex Grouping Query

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

问题描述

下面是我的sql查询,我已经放了一些MAX(table_name),因为当使用group by时我不能只放表名。如果我放了MAX,那么当有varchar值时需要时间来执行,请给我varchar而不是MAX的好聚合函数。



另外,那些MAX( table_name)都是相同的值,没有什么不同,我只需要打印它。



Below is my sql query, I have put some MAX(table_name) because when group by is used I can't just put the table name. If I put MAX, it will take time to execute when there is varchar values, please give me good aggregate function for varchar instead of MAX.

Also, those MAX(table_name) all are same values, no different, I just need to print it.

select distinct t1.PartyName as Customer_Name, SUM(t2.Amount) as Bill_Amount, MAX(t2.VoucherNumber) as Invoice_Number, SUM(i.Weight * t2.Aqty) as Weight, CEILING(SUM(i.CBM * (t2.Aqty/c.Nos))) as CBM, MAX(p.Channel) as Type, MAX(p.RouteNo) as RouteNo, MAX(t1.Adress3) as City
from Item i, Party p, Tran1 t1, VTran2 t2, Cases c
Where t1.VoucherNumber=t2.VoucherNumber and t2.ItemName=i.Itemname and p.PartyName=t1.PartyName and t2.ItemName=c.ItemName and p.RouteNo='" + routeNo1comboBox.Text + "' and t1.LoadingStatus IS NULL and t1.Date BETWEEN '" + startDate + "' and '" + endDate + "' GROUP BY t1.PartyName", cs);

推荐答案

如果MAX(table_name)都是相同的值,没有区别,那么在group by中添加这些列名,就不需要将聚合函数添加到列名中。
If MAX(table_name) all are same values, no different then add those column names in group by, you will not need to add aggregate function to the column name.


这篇关于复杂分组查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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