sql语句报错,怎么修改?

ice241018 2007-12-05 10:33:29
select a.*,b.*, c.*,d.* from dghouseinfo a,dghouseprice b left join (select top 1 * from dghousepic e where e.newcode = a.newcode) c on c.newcode=a.newcode left join dghousepeitao d on d.newcode=c.newcode where a.newcode=b.newcode order by a.id desc
在查询分析器里运行老是报错
服务器: 消息 107,级别 16,状态 2,行 1
列前缀 'a' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,行 1
列前缀 'a' 与查询中所用的表名或别名不匹配。
...全文
526 37 打赏 收藏 转发到动态 举报
写回复
用AI写文章
37 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjlhch 2007-12-10
  • 打赏
  • 举报
回复
jf
shmlove521 2007-12-10
  • 打赏
  • 举报
回复
看看是不是表的存储过程里面的名称和 创建的表名称是否相同,对于系统提示的错误要耐心的调试
DengXingJie 2007-12-10
  • 打赏
  • 举报
回复
标记下
wenwt7 2007-12-10
  • 打赏
  • 举报
回复
晕死。

4个表的联接跟2个表其实没什么区别的。
建议在联接一个表以后加上括号。
比较便于阅读。
shirley_yueli 2007-12-10
  • 打赏
  • 举报
回复
学习
andy84 2007-12-10
  • 打赏
  • 举报
回复
标记下
十一月猪 2007-12-10
  • 打赏
  • 举报
回复
友情接分
-狙击手- 2007-12-08
  • 打赏
  • 举报
回复
接分,给小楼开贴通知 我再接分
lichengwu22 2007-12-08
  • 打赏
  • 举报
回复
学习了!
neituib 2007-12-08
  • 打赏
  • 举报
回复
希望找到更合适的工作,也许通过内部推荐能更容易成功

内推网 内部推荐,求职快线
ice241018 2007-12-06
  • 打赏
  • 举报
回复
ice241018 2007-12-06
  • 打赏
  • 举报
回复
跟这个问题一样
但是我要的是通用的语句啊
jianswu 2007-12-06
  • 打赏
  • 举报
回复
select * from dghousepic e where 某列=(select top 1 某列 from dghousepic where newcode=e.newcode

????
真搞不懂你想干嘛,你如果能把意图说明白点,或许早有人帮你解决了
dawugui 2007-12-06
  • 打赏
  • 举报
回复
你把数据,结构,算法和结果拿出来,不然头大.
Limpire 2007-12-06
  • 打赏
  • 举报
回复
declare @dghousepic table (newcode int, image varbinary(10))
insert @dghousepic select 1, 0x1
insert @dghousepic select 1, 0x2
insert @dghousepic select 1, 0x3
insert @dghousepic select 2, 0xa
insert @dghousepic select 2, 0xb
insert @dghousepic select 2, 0xc

--> 都说了某列是指在单个newcode内是唯一的:
select * from @dghousepic a where image=(select top 1 image from @dghousepic where newcode=a.newcode)
/*
newcode image
----------- ---------
1 0x01
2 0x0A
*/

--> 加个重复的
insert @dghousepic select 1, 0x1 -->这张照片重复,而且 top 1 刚好命中
select * from @dghousepic a where image=(select top 1 image from @dghousepic where newcode=a.newcode)
/*
newcode image
----------- ---------
1 0x01
2 0x0A
1 0x01
*/

--> 生成唯一的识别码处理:2000
select id=identity(int,1,1),* into #dghousepic from @dghousepic
select newcode,image from #dghousepic a where id=(select top 1 id from #dghousepic where newcode=a.newcode)

/*
newcode image
----------- ---------
1 0x01
2 0x0A
*/

--> 生成唯一的识别码处理:2005
;with cte (id,newcode,image) as
(
select row_number() over (order by newcode),* from @dghousepic
)
select newcode,image from cte a where id=(select top 1 id from cte where newcode=a.newcode)
/*
newcode image
----------- ---------
1 0x01
2 0x0A
*/
ice241018 2007-12-06
  • 打赏
  • 举报
回复
to 昨夜小楼
select
a.*,
b.*,
c.*,
d.*
from
dghouseinfo a
inner join
dghouseprice b
on a.newcode=b.newcode
left join
(select * from dghousepic e where 某列=(select top 1 某列 from dghousepic where newcode=e.newcode)) c
on c.newcode=a.newcode
left join
dghousepeitao d
on d.newcode=c.newcode
order by a.id desc
老大,语句是没有问题了
但是dghousepic中的数据还是有重复显示啊
我的意思是
dghousepic,dghouseprice,dghousepeitao中有重复newcode,只显示一条数据,其他不显示,任何一条都行。
问题解决,我再追加你100分
感激不尽,谢谢

fangshk2007 2007-12-06
  • 打赏
  • 举报
回复
我晕
(select top 1 * from dghousepic e where e.newcode = a.newcode) c
是一张表吗?
怎么会有这么条SQL语句呢?
neituib 2007-12-06
  • 打赏
  • 举报
回复
想换个跟好的跟适合的工作,也许可以通过内部推荐更容易实现

内推网 内部推荐,求职快线
ice241018 2007-12-06
  • 打赏
  • 举报
回复
up
meimei_yan 2007-12-06
  • 打赏
  • 举报
回复
厉害
加载更多回复(17)

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧