Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1389|回复: 3
打印 上一主题 下一主题

【已解决】 SQL Group By 问题

[复制链接]

14

主题

2

好友

734

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

跳转到指定楼层
1#
发表于 2012-8-15 01:52 PM |只看该作者 |倒序浏览
本帖最后由 shinn1080 于 2012-8-16 10:11 AM 编辑

各位好
  1. select empPhoto.ImageData,upduser, count(upduser) as totalView   from efview  left join empPhoto on empPhoto.emp_id = efview.upduser where docid = '1' and version ='1.00' group by efview.updUser
复制代码
出现的error如下
Msg 8120, Level 16, State 1, Line 1
Column 'empPhoto.ImageData' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

可是拿掉empPhoto.ImageData就没事了,但是我非常需要这个field。不太清楚group by的用法,参考网上的资料还是没头绪。
请高手指点。




收藏收藏0

6

主题

0

好友

397

积分

超级会员

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

2#
发表于 2012-8-15 06:16 PM |只看该作者
你确定 empPhoto 里有 ImageData 这个field?
最好你能把两个Table的field都写出来,不然很难猜测实际情况


回复

使用道具 举报

5

主题

0

好友

318

积分

超级会员

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

3#
发表于 2012-8-15 10:16 PM |只看该作者
  1. select empPhoto.ImageData,upduser, count(upduser) as totalView   from efview  left join empPhoto on empPhoto.emp_id = efview.upduser where docid = '1' and version ='1.00' group by efview.updUser, empPhoto.ImageData
复制代码
试试看可以吗?太久没用sql command没办法直接帮你test。


回复

使用道具 举报

14

主题

2

好友

734

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

4#
发表于 2012-8-16 10:11 AM |只看该作者
http://zhidao.baidu.com/question/464583113.html?oldq=1
  1. select t.*,p.ImageData  from (
  2. select t.upduser, COUNT(1) as totalView  from efView t
  3. group by t.updUser ) t
  4. left join empPhoto p on t.upduser = p.emp_id
复制代码
解决了^^


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-26 12:22 AM , Processed in 0.119004 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部