首页 新闻 会员 周边

关于Group问题

0
悬赏园豆:5 [已解决问题] 解决于 2008-08-15 11:54
<P>PKId Title Datatime B_PIKd</P> <P>1&nbsp;title&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;NULL&nbsp; &nbsp;2<BR>2&nbsp;title&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;NULL&nbsp;&nbsp; 1<BR>3&nbsp;title&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;NULL&nbsp;&nbsp; &nbsp;2<BR>4&nbsp;title&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;NULL&nbsp;&nbsp; 3<BR>5&nbsp;title&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;NULL&nbsp; &nbsp;3<BR>6&nbsp;title&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;NULL&nbsp;&nbsp; 3<BR>7&nbsp;title&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;NULL&nbsp;&nbsp; 3<BR>8&nbsp;title&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;NULL&nbsp; &nbsp;1</P> <P>&nbsp;</P> <P>select * from News group by B_PKId&nbsp; 这条为什么报错</P> <P>消息 8120,级别 16,状态 1,第 1 行<BR>选择列表中的列 'News.PKId' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。</P>
汉城的主页 汉城 | 初学一级 | 园豆:2
提问于:2008-08-13 11:23
< >
分享
最佳答案
0
USE AdventureWorks; GO SELECT SalesOrderID, SUM(LineTotal) AS SubTotal FROM Sales.SalesOrderDetail sod GROUP BY SalesOrderID ORDER BY SalesOrderID ; GO 给你个链接自己去看看关于group by 的用法 http://msdn.microsoft.com/zh-cn/library/ms189288.aspx
有所为,有所不为 | 小虾三级 |园豆:1200 | 2008-08-15 09:00
其他回答(4)
0
GROUP BY 是配合聚合语句用的 select count(*) , B_PKId from News group by B_PKId 只group by中能够不用聚合函数表示的只有被group by 的项
小眼睛老鼠 | 园豆:2731 (老鸟四级) | 2008-08-13 11:39
0
GROUP BY 语句中 SELECT中的东西必须包含在聚合语句里,或者是聚合函数,比如COUNT AVG MAX等。楼主的要求可以用 SELECT *,A.count FROM News INNER JOIN (select COUNT(*) AS count from News group by B_PKId ) AS A WHERE a.B_PKId = News.B_PKId
zeus2 | 园豆:92 (初学一级) | 2008-08-13 12:10
0
group by是分组的意思,分组就有按照什么分组,然后还有分组每组的聚合值是什么。 看看基础的sql语句吧,理解了就明白为啥错了。
玉开 | 园豆:8822 (大侠五级) | 2008-08-13 13:31
0
1、3楼都说了,看SQL基础是最重要的
AndyFish | 园豆:1575 (小虾三级) | 2008-08-14 09:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册