SQL MAX()返回不同的值 [英] SQL MAX() to return a different value

查看:305
本文介绍了SQL MAX()返回不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我有一张桌子,上面有图像的文件位置及其大小作为字段.我想返回最大图像的字段位置字段.使用MAX(fieldsize)可以得到正确的记录,但是如何返回不同的字段呢?

Hello,
I have a table with the file location of images and their sizes as fields. I want to return the fiel location field of the largest image. Using MAX(fieldsize) gets me the right record, but how do I return a different field?

SELECT MAX(fldItemSize) FROM tblItemImagePaths
    WHERE fldSupplierID = @SupplierID
    AND fldSupplierCode = @SupplierCode



当我包含需要查询的字段时,查询将返回两行数据.是的,我是这个新手:)



when I include the requried field, the query then returns two lines of data. Yes, I''m new to this :)

SELECT        MAX(fldItemSize) AS Expr1, fldItemPath
FROM            tblItemImagePaths
WHERE        (fldSupplierID = @SupplierID) AND (fldSupplierCode = @SupplierCode)
GROUP BY fldItemPath

推荐答案

从tblItemImagePaths中选择前1个myfield,其中... ORDER BY fldItemSize DESC

是一种显而易见的方法.

从tblITemImagePaths中选择myfield,其中.... AND fldItemSize = MAX(fldItemSize)

是另一个.
select top 1 myfield from tblItemImagePaths where ... ORDER BY fldItemSize DESC

is one obvious way to go.

select myfield from tblITemImagePaths where .... AND fldItemSize = MAX(fldItemSize)

is another.


这篇关于SQL MAX()返回不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆