下面是我的sql查询,我已经放了一些MAX(table_name),因为当使用group时,我不能只放置表名。如果我把MAX,它将需要时间来执行时,有varchar值,请给我好的聚合函数的varchar,而不是MAX。
另外,那些MAX(table_name)都是相同的值,没有什么不同,我只是需要打印出来。
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发布于 2014-12-03 12:39:22
“而且,那些MAX(table_name)都是相同的值,没有什么不同,我只是需要打印出来。”
为什么不能将它们添加到选择列表和组中呢?
这个不行吗?
select distinct
t1.PartyName as Customer_Name,
SUM(t2.Amount) as Bill_Amount,
t2.VoucherNumber as Invoice_Number,
SUM(i.Weight * t2.Aqty) as Weight,
CEILING(SUM(i.CBM * (t2.Aqty/c.Nos))) as CBM,
p.Channel as Type,
p.RouteNo as RouteNo,
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,t2.VoucherNumber,p.Channel,p.RouteNo,t1.Adress3https://stackoverflow.com/questions/27271812
复制相似问题