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

在 WHERE 條件下獲取 SQL 中的最后一條記錄

Getting the last record in SQL in WHERE condition(在 WHERE 條件下獲取 SQL 中的最后一條記錄)
本文介紹了在 WHERE 條件下獲取 SQL 中的最后一條記錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有 loanTable 包含兩個字段 loan_idstatus

i have loanTable that contain two field loan_id and status

loan_id status
==============
1       0
2       9
1       6
5       3
4       5
1       4  <-- How do I select this??
4       6

在這種情況下,我需要顯示 loan_id 1 的最后一個 Status,即 status 4.請幫助我進行此查詢.

In this Situation i need to show the last Status of loan_id 1 i.e is status 4. Can please help me in this query.

推薦答案

由于 ID 1 的最后"行既不是最小值也不是最大值,因此您處于一種輕微的混亂狀態.表中的行沒有順序.因此,您應該提供另一列,可能是插入每一行的日期/時間,以提供數據的排序.另一種選擇可能是一個單獨的、自動遞增的列,它記錄插入行的順序.然后查詢就可以寫了.

Since the 'last' row for ID 1 is neither the minimum nor the maximum, you are living in a state of mild confusion. Rows in a table have no order. So, you should be providing another column, possibly the date/time when each row is inserted, to provide the sequencing of the data. Another option could be a separate, automatically incremented column which records the sequence in which the rows are inserted. Then the query can be written.

如果額外的列被稱為status_id,那么你可以寫:

If the extra column is called status_id, then you could write:

SELECT L1.*
  FROM LoanTable AS L1
 WHERE L1.Status_ID = (SELECT MAX(Status_ID)
                         FROM LoanTable AS L2
                        WHERE L2.Loan_ID = 1);

(表別名 L1 和 L2 可以省略,不會混淆 DBMS 或有經驗的 SQL 程序員.)

(The table aliases L1 and L2 could be omitted without confusing the DBMS or experienced SQL programmers.)

就目前而言,沒有可靠的方法知道哪一行是最后一行,因此您的查詢無法回答.

As it stands, there is no reliable way of knowing which is the last row, so your query is unanswerable.

這篇關于在 WHERE 條件下獲取 SQL 中的最后一條記錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Sql server table usage statistics(Sql server 表使用情況統計)
Relative path in t sql?(t sql中的相對路徑?)
Query to get XML output for hierarchical data using FOR XML PATH in SQL Server(在 SQL Server 中使用 FOR XML PATH 查詢以獲取分層數據的 XML 輸出)
T-SQL IF statement embedded in a sum() function(嵌入在 sum() 函數中的 T-SQL IF 語句)
Table vs Temp Table Performance(表與臨時表性能)
Can#39;t see created tables in Object Explorer - Microsoft SQL Management Studio(在對象資源管理器中看不到創建的表 - Microsoft SQL Management Studio)
主站蜘蛛池模板: 男女无遮挡xx00动态图120秒 | 狠狠综合网 | 国产精品欧美精品 | 欧美专区在线观看 | 亚洲一区在线视频 | 久久久久国产视频 | 精品国产一区二区三 | 亚洲高清在线视频 | 99re在线| 97国产精品人人爽人人做 | 成人三级视频 | 国产精品一区二区三区四区五区 | 国产成人一区二区三区 | 又黄又爽的网站 | 成人爽a毛片一区二区免费 www.欧美精品 | 怡红院亚洲 | 成人精品影院 | 一本一道久久a久久精品蜜桃 | 特黄一级片 | 国产欧美日韩综合 | 久久九九精品 | www.夜夜操| 91小视频在线观看 | 午夜激情在线观看 | 一区二区不卡视频 | 日本a视频 | 国产精品久久久精品 | 欧美手机在线 | 精品国产欧美一区二区三区成人 | 精品日韩在线 | av永久免费| 91播放 | 欧美色图一区 | 国产精品乱 | 日韩免费观看 | 国产一二三 | 中文字幕欧美激情 | 荤话粗俗h高h重口 | 性色av网站| 成人在线免费视频观看 | 成人蜜桃视频 |