<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    問(wèn)題:
    在BBS中,content 和? review 兩張表,其中content 記錄的是 帖子信息(topic_id,topic_title,topic_content等字段),review 表中記錄的是回帖的信息,(review_id,topic_id等字段)在 求一SQL語(yǔ)句,其中topic_id和review_id都是自動(dòng)增加,現(xiàn)在要求查詢出有最新回復(fù)的帖子的信息,同時(shí)要求有多個(gè)回復(fù)的一個(gè)帖子的主題只能顯示一次,能用一個(gè)SQL語(yǔ)句搞定嗎?數(shù)據(jù)庫(kù)是MYSQL 求高手指點(diǎn)下

    回答:
    select t.id,t.title,t.content,r.newposttime from topic as t inner join (select max(posttime) as newposttime, topicid from review group by topicid) as r on t.id=r.topicid
    ?
    //測(cè)試
    create table topic(
    ? id int primary key identity(1,1),
    ? title varchar(128),
    ? content text
    )

    insert into topic(title,content) values('title1','content1')
    insert into topic(title,content) values('title1','content1')
    insert into topic(title,content) values('title1','content1')
    insert into topic(title,content) values('title1','content1')
    insert into topic(title,content) values('title1','content1')
    insert into topic(title,content) values('title1','content1')
    insert into topic(title,content) values('title1','content1')
    insert into topic(title,content) values('title1','content1')
    insert into topic(title,content) values('title1','content1')
    insert into topic(title,content) values('title1','content1')


    create table review(
    ? id int primary key identity(1,1),
    ? topicid int references topic(id),
    ? content text,
    ? posttime datetime default getdate()
    )

    insert into review(topicid,content) values(1,'reice1')
    insert into review(topicid,content) values(1,'reice1')
    insert into review(topicid,content) values(2,'reice1')
    insert into review(topicid,content) values(2,'reice1')
    insert into review(topicid,content) values(2,'reice1')
    insert into review(topicid,content) values(3,'reice1')
    insert into review(topicid,content) values(3,'reice1')
    insert into review(topicid,content) values(3,'reice1')
    insert into review(topicid,content) values(3,'reice1')
    insert into review(topicid,content) values(4,'reice1')

    select t.id,t.title,t.content,r.newposttime from topic as t inner join (select max(posttime) as newposttime, topicid from review group by topicid) as r on t.id=r.topicid

    這些是測(cè)試數(shù)據(jù),sqlserver2000測(cè)試通過(guò)

    posted on 2006-09-28 18:49 pear 閱讀(459) 評(píng)論(0)  編輯  收藏 所屬分類: 心得體會(huì)
     
    主站蜘蛛池模板: 亚洲一级毛片免费看| 日本在线看片免费| 永久免费av无码网站大全| 亚洲视频在线观看2018| 国产一卡2卡3卡4卡2021免费观看| 亚洲邪恶天堂影院在线观看| 四虎国产精品永久免费网址| 亚洲av色影在线| 18未年禁止免费观看| 亚洲成a人不卡在线观看| 999久久久免费精品国产| 亚洲粉嫩美白在线| 国产自产拍精品视频免费看| 极品美女一级毛片免费| 亚洲人成中文字幕在线观看| 一级毛片全部免费播放| 久久狠狠爱亚洲综合影院| 日本高清免费中文字幕不卡| 一级特黄aaa大片免费看| 亚洲美国产亚洲AV| 国产精品视频免费一区二区三区| 一级毛片在播放免费| 亚洲av无码专区国产乱码在线观看 | 最好看最新的中文字幕免费| 亚洲综合久久一本伊伊区| 国产又粗又长又硬免费视频| 国产免费久久精品丫丫| 77777_亚洲午夜久久多人| 好男人www免费高清视频在线| 免费亚洲视频在线观看| 亚洲日韩精品一区二区三区| 日本免费网址大全在线观看| 国产精品自拍亚洲| 亚洲精品无码久久久影院相关影片| 亚洲一区免费观看| 亚洲6080yy久久无码产自国产 | 国产精品hd免费观看| 亚洲AV永久无码精品成人| 99久久免费国产精品特黄| 污网站在线免费观看| 亚洲成a人片在线观看中文动漫|