imgzoom表: zoomid(主键), zoomtittle
imginfo表:imgid(主键),imgtittle,imgdesp,imgsmall,zoomid(外键)
在存储过程中实现:
查询:zoomtittle,imgsmall,zoomid 这三个字段(列)
前提:imginfo表中有相同zoomid的时候,只取第一条记录
没分了,只能发非技术贴
5 个解决方案
#1
SELECT A.zoomtittle,B.imgsmall,B.zoomid
FROM imgzoom A CROSS APPLY(SELECT TOP(1)* FROM imginfo B WHERE A.zoomid=B.zoomid ORDER BY NEWID()) B
#2
谢谢了,功能基本实现了,但是有点问题,就是在绑定imgsmall的时候,刷新页面会变化,好像随机的,不是每次都会变,什么问题呢。这样效果也行
#3
我是随机取一条,所以每次都不一样。
SELECT A.zoomtittle,B.imgsmall,B.zoomid
FROM imgzoom A CROSS APPLY(SELECT TOP(1)* FROM imginfo B WHERE A.zoomid=B.zoomid order by imgid) B
这样那个就行了
#4
SELECT a.zoomtittle,b.imgsmall,a.zoomid
FROM imgzoom a
LEFT JOIN
(
SELECT number = ROW_NUMBER() OVER(PARTITION BY zoomid ORDER BY GETDATE()),* FROM imginfo
) b
ON a.zoomid = b.zoomid AND b.number = 1
#5
select a.* from imgzoom a left join
( select * from imginfo where imgid in (select min(imgid) from imginfo group by zoomid))
b on a.[zoomid]=b.[zoomid]
#1
SELECT A.zoomtittle,B.imgsmall,B.zoomid
FROM imgzoom A CROSS APPLY(SELECT TOP(1)* FROM imginfo B WHERE A.zoomid=B.zoomid ORDER BY NEWID()) B
#2
谢谢了,功能基本实现了,但是有点问题,就是在绑定imgsmall的时候,刷新页面会变化,好像随机的,不是每次都会变,什么问题呢。这样效果也行
#3
我是随机取一条,所以每次都不一样。
SELECT A.zoomtittle,B.imgsmall,B.zoomid
FROM imgzoom A CROSS APPLY(SELECT TOP(1)* FROM imginfo B WHERE A.zoomid=B.zoomid order by imgid) B
这样那个就行了
#4
SELECT a.zoomtittle,b.imgsmall,a.zoomid
FROM imgzoom a
LEFT JOIN
(
SELECT number = ROW_NUMBER() OVER(PARTITION BY zoomid ORDER BY GETDATE()),* FROM imginfo
) b
ON a.zoomid = b.zoomid AND b.number = 1
#5
select a.* from imgzoom a left join
( select * from imginfo where imgid in (select min(imgid) from imginfo group by zoomid))
b on a.[zoomid]=b.[zoomid]