这个GROUP BY怎么样才可以呀?(SQL ERERVER 2000)(10分)

  • 主题发起人 主题发起人 tt123tt
  • 开始时间 开始时间
T

tt123tt

Unregistered / Unconfirmed
GUEST, unregistred user!
下面这个是到行正常的:
SELECT company AS Expr4, SUM(heft) AS Expr2, AVG(price) AS Expr1, SUM(tot) AS Expr3,
sort
FROM dbo.xh_waste
GROUP BY company, sort
我把它改成这样就不行了:
SELECT company AS Expr4, SUM(heft) AS Expr2, AVG(price) AS Expr1, SUM(tot) AS Expr3,
sort
FROM dbo.xh_waste
GROUP BY company   (不想用 sort分类但要列出SORT)
怎样才可以不用SORT分类但要列出SORT?
 
SELECT company AS Expr4, SUM(heft) AS Expr2, AVG(price) AS Expr1, SUM(tot) AS Expr3,
(select top 1 sort from dbo.xh_waste where company=AA.company)
FROM dbo.xh_waste AA
GROUP BY company 
 
你要列出sort就必须用sort分组,否则同一类company中有不同的sort怎么显示呢?
 
同意stuwei
你首先想好同一类company中有不同的sort你想让它怎么显示,
然后再来写语句,
 
创见一视图
 
我要列出SORT 的目的是要用SORT 做主从表,
我做的这个是流水帐的月报表用算出SORT(地区)地每一个点(COMOPANY)的月销售量和销售总金额
大家还有没有别的好办法?请多指教!
 
后退
顶部