0

一张桌子

MODEL(IDMODEL inc., NAME text)

一张桌子

DOC(IDDOC inc., NAME text, RELEASE numeric, IDMODEL numeric)

DOC 中的记录证实DOC.IDMODEL == MODEL.IDMODEL.

我想从中选择DOC具有最大值的所有记录RELEASE

模型数据:

"1" "specification"
"2" "cahier de test"

来自 DOC 的数据:

iddoc   name        release idmodel
"1" "doc 1.1"   "1" "1"
"2" "doc 1.2"   "2" "1"
"3" "doc 2.1"   "1" "2"
"4" "doc 2.2"   "2" "2"
"5" "doc 2.3"   "3" "2"  > required
"6" "doc 1.3"   "3" "1"
"7" "doc 1.4"   "4" "1"  > required
"8" "doc 2 bis.1"   "1" "2"
"9" "doc 2 bis.2"   "2" "2"
"10" "doc 2 bis.3"  "3" "2"  > required

你能帮我做 SELECT 命令吗?

此致。

4

2 回答 2

1

通过使用子选择尝试这种方式:

SELECT * 
FROM DOC 
WHERE release=(
    SELECT max(release) FROM DOC
    )

或者

 SELECT * from DOC ORDER BY release DESC LIMIT 1;
于 2013-10-19T09:17:54.940 回答
0

如果我正确理解您的问题,这应该返回您需要的行:

SELECT doc.*
FROM
  doc INNER JOIN (SELECT idmodel, MAX(release) As max_release
                  FROM doc
                  GROUP BY idmodel) mx
  ON doc.idmodel = mx.idmodel AND doc.release=max_release

在此处查看小提琴。

于 2013-10-19T09:33:13.830 回答