pnews表
----------------------------------
pnewsid title source appenddate
12 123 123 2007-01-26 17:14:48.000
13 12 中心 2007-01-26 00:00:00.000
14 111 1 2007-01-26 00:00:00.000
15 11 中心 2007-01-26 00:00:00.000
16 11 中心 2007-01-26 00:00:00.000
17 1212 中心 2007-01-26 00:00:00.000
18 1212 中心 2007-01-26 00:00:00.000
19 1212 中心 2007-01-26 00:00:00.000
20 323 中心 2007-01-26 00:00:00.000
21 1··1 中心 2007-01-26 00:00:00.000pictures表
-----------------------------------------------------------------------
pid pnewsid pname pintr place
21 12 noimage.gif 1
22 12 noimage.gif 无介绍 0
23 13 noimage.gif 无介绍 0
24 14 4ced4.gif 上铺image 1
25 14 f58f0f.jpg iyang 2
26 14 adbfe4.jpg you yige taiyang 3
27 14 4ced4.gif 1 0
28 14 4ced4.gif 2 0
29 14 4ced4.gif 3 0
30 14 4ced4.gif 4 0
31 14 4ced4.gif 5 0-----------------------------------------------------------我现在想要的结果就是
pictures表里头去掉pnewsid这个字段重复的记录,然后跟pnews表里头的title字段的组合形式如:
------------------------------
pid pnewsid title pname
22 12 123 noimage.gif
23 13 12 noimage.gif
24 14 111 4ced4.gif
万分感谢!!!
----------------------------------
pnewsid title source appenddate
12 123 123 2007-01-26 17:14:48.000
13 12 中心 2007-01-26 00:00:00.000
14 111 1 2007-01-26 00:00:00.000
15 11 中心 2007-01-26 00:00:00.000
16 11 中心 2007-01-26 00:00:00.000
17 1212 中心 2007-01-26 00:00:00.000
18 1212 中心 2007-01-26 00:00:00.000
19 1212 中心 2007-01-26 00:00:00.000
20 323 中心 2007-01-26 00:00:00.000
21 1··1 中心 2007-01-26 00:00:00.000pictures表
-----------------------------------------------------------------------
pid pnewsid pname pintr place
21 12 noimage.gif 1
22 12 noimage.gif 无介绍 0
23 13 noimage.gif 无介绍 0
24 14 4ced4.gif 上铺image 1
25 14 f58f0f.jpg iyang 2
26 14 adbfe4.jpg you yige taiyang 3
27 14 4ced4.gif 1 0
28 14 4ced4.gif 2 0
29 14 4ced4.gif 3 0
30 14 4ced4.gif 4 0
31 14 4ced4.gif 5 0-----------------------------------------------------------我现在想要的结果就是
pictures表里头去掉pnewsid这个字段重复的记录,然后跟pnews表里头的title字段的组合形式如:
------------------------------
pid pnewsid title pname
22 12 123 noimage.gif
23 13 12 noimage.gif
24 14 111 4ced4.gif
万分感谢!!!
from (select ... from pictures,pnews where pnews.pnewsid=pictures.pnewsid) a
(
select a.* from pictures a,
(select pid , min(pnewsid) as pnewsid from pictures group by pid) b
where a.pid = b.pid and a.pnewsid = b.pnewsid
) n
where m.pnewsid = n.pnewsid
----------------------------------
pnewsid title source appenddate
12 123 123 2007-01-26 17:14:48.000
13 12 中心 2007-01-26 00:00:00.000
14 11 11 2007-01-26 00:00:00.000
15 11 中心 2007-01-26 00:00:00.000
16 11 中心 2007-01-26 00:00:00.000
17 1212 中心 2007-01-26 00:00:00.000
18 1212 中心 2007-01-26 00:00:00.000
19 1212 中心 2007-01-26 00:00:00.000
20 323 中心 2007-01-26 00:00:00.000
21 1··1 中心 2007-01-26 00:00:00.000pictures表
-----------------------------------------------------------------------
pid pnewsid pname pintr place
21 12 noimage.gif 1
22 12 noimage.gif 无介绍 0
23 13 noimage.gif 无介绍 0
24 14 4ced4.gif 上铺image 1
25 14 f58f0f.jpg iyang 2
26 14 adbfe4.jpg you yige taiyang 3
27 14 4ced4.gif 1 0
28 14 4ced4.gif 2 0
29 14 4ced4.gif 3 0
30 14 4ced4.gif 4 0
31 14 4ced4.gif 5 0-----------------------------------------------------------我现在想要的结果就是
pictures表里头去掉pnewsid这个字段重复的记录,然后跟pnews表里头的title字段的组合形式如:
------------------------------
pid pnewsid title pname
22 12 123 noimage.gif
23 13 12 noimage.gif
24 14 111 4ced4.gif
pid=max(pid),
pnewsid,
title=(select title from pnews where pnewsid=tmp.pnewsid),
pname=max(pname)
from pictures as tmp
group by pnewsid--result
pid pnewsid title pname
----------- ----------- ---------- --------------------
22 12 123 noimage.gif
23 13 12 noimage.gif
31 14 11 f58f0f.jpg(3 row(s) affected)