久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 SQL Server 中包含多行數據的 2 個表中選擇

How can I select 4 distinct values from 2 tables containing many rows of data in SQL Server?(如何從 SQL Server 中包含多行數據的 2 個表中選擇 4 個不同的值?)
本文介紹了如何從 SQL Server 中包含多行數據的 2 個表中選擇 4 個不同的值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有 2 個表,我試圖從 GalleryID DESC 的排序中選擇 4 個結果.我希望返回的字段是 Gallery 表中的 GalleryID、GalleryTitle、GalleryDate 和 Media 表中的 MediaThumb.

I have 2 tables that Im trying to select 4 results from ordered by GalleryID DESC. The fields Im looking to return are GalleryID, GalleryTitle, GalleryDate from the Galleries table, and MediaThumb from the Media Table.

現在問題是 Media 表具有 GalleryID 的 10 的倍數.因此,Media 表中可能有 10 行具有相同的 GalleryID.我所需要的只是一個 MediaThumb 來配合galleryid.

Now the catch is that the Media table has multiples of 10 of GalleryID's. So, there could be 10 rows in the Media table with the same GalleryID. All I need is one MediaThumb to go along with the galleryid.

我不確定如何制定查詢以從畫廊表中返回 4 個不同的畫廊 ID,并從媒體表中返回一個 MediaThumb.

Im not sure how to formulate a query to return 4 distinct galleryid's from the galleries table and a MediaThumb from the media table.

基本上,我想要做的是返回 4 個獨特的照片畫廊,其中包含一張來自媒體表的封面照片.

Essentially what im trying to do is return 4 unique photo galleries with a cover photo from the media table.

任何幫助將不勝感激.我通過 sqlserver 中的查詢設計器提供了我的 2 個表的快照.

Any help would be appreciated. I provided a snapshot via query designer in sqlserver of my 2 tables.

推薦答案

類似的事情?

SELECT TOP 4 
    g.GalleryID
    ,g.GalleryTitle
    ,g.GalleryDate
    ,MAX(m.MediaThumb) AS MaxMediaThumb
FROM Galleries g
    INNER JOIN Media m
        ON g.GalleryID = m.GalleryID
GROUP BY g.GalleryID, g.GalleryTitle, g.GalleryDate

這篇關于如何從 SQL Server 中包含多行數據的 2 個表中選擇 4 個不同的值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 欧美一极视频 | 红色av社区 | 日本不卡免费新一二三区 | 麻豆a级片| 日韩中文字幕一区二区 | 亚洲高清在线观看 | 91在线看片| 麻豆一区二区三区精品视频 | 97精品超碰一区二区三区 | 欧美精品一区二区三区在线 | 黑人性hd| 精品一区二区免费视频 | 国产综合第一页 | www久久国产 | 国产精品视频免费看 | 91porn国产成人福利 | 日韩精品区 | 国产精品视频久久 | 国产精品福利久久久 | 国产欧美在线一区二区 | 亚洲一本 | 精品国产一区二区三区性色av | 999精品视频在线观看 | 亚洲日本免费 | 男人天堂99 | 99精品视频免费观看 | 国产精品国产精品国产专区不卡 | 国产精品久久久久久久久久久久 | 国产一区二区美女 | 日韩av大片免费看 | 日韩欧美久久 | 热re99久久精品国产99热 | 正在播放亚洲 | 艹逼网 | 免费一区 | 一区二区在线 | 亚洲视频 欧美视频 | 日韩在线三级 | 亚洲九色| 天天操天天射综合网 | 欧美精品中文字幕久久二区 |