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

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

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

    問題:
    在BBS中,content 和? review 兩張表,其中content 記錄的是 帖子信息(topic_id,topic_title,topic_content等字段),review 表中記錄的是回帖的信息,(review_id,topic_id等字段)在 求一SQL語句,其中topic_id和review_id都是自動增加,現在要求查詢出有最新回復的帖子的信息,同時要求有多個回復的一個帖子的主題只能顯示一次,能用一個SQL語句搞定嗎?數據庫是MYSQL 求高手指點下

    回答:
    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
    ?
    //測試
    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

    這些是測試數據,sqlserver2000測試通過

    posted on 2006-09-28 18:49 pear 閱讀(459) 評論(0)  編輯  收藏 所屬分類: 心得體會
     
    主站蜘蛛池模板: 国产三级在线免费观看| 24小时在线免费视频| 一级做a爰片久久毛片免费陪| 2022免费国产精品福利在线| 19禁啪啪无遮挡免费网站| 亚洲va在线va天堂va不卡下载| 亚洲一区中文字幕在线电影网| 色婷婷综合缴情综免费观看| 国产免费久久精品久久久| 亚洲精品人成电影网| 精品久久久久久国产免费了| 国内精品99亚洲免费高清| 国产午夜亚洲精品| 午夜理伦剧场免费| 黑人大战亚洲人精品一区| 成人无码区免费A∨直播| 四虎永久免费观看| 国产特黄特色的大片观看免费视频| 亚洲综合精品香蕉久久网| 日韩精品无码免费专区午夜| 天天操夜夜操免费视频| 青青草国产免费国产是公开| 亚洲av日韩专区在线观看| 亚洲成年人免费网站| 国产成人精品日本亚洲18图| 日本xxxx色视频在线观看免费| 亚洲国产精品自在拍在线播放| 中文字幕亚洲综合久久综合 | 亚洲一区二区精品视频| 日韩亚洲国产高清免费视频| 日日夜夜精品免费视频| 亚洲国产区男人本色| 好男人www免费高清视频在线| 亚洲第一页在线观看| 好爽…又高潮了毛片免费看| 亚洲五月午夜免费在线视频| 亚洲一区二区在线视频| 4399影视免费观看高清直播| 亚洲av无码日韩av无码网站冲| 曰韩亚洲av人人夜夜澡人人爽| 91精品国产免费久久久久久青草|