在视图SQL Server中返回值的最大值 [英] Return max of the value in view SQL Server
本文介绍了在视图SQL Server中返回值的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了此视图,如您在此处看到的:
I created this view as you can see here :
我的看法是这样的:
但是实际上我需要两个值:fitupdetailid
和'weldetaildid'的最大记录.
but in fact I need two values: the max record of fitupdetailid
and `weldetaildid.
我是SQL查询的新手.我可以在视图中添加一些过滤器吗?
I am new to SQL query. Can I add some filter to my view?
SELECT
dbo.fitupdetail.fitupdetailId, dbo.jointId.JointId,
dbo.weldDetail.WeldDetailId
FROM
dbo.weldDetail
INNER JOIN
dbo.jointId ON dbo.weldDetail.jointid = dbo.jointId.JointId
INNER JOIN
dbo.fitupdetail ON dbo.jointId.JointId = dbo.fitupdetail.jointid
我的意思是
101-2-51
201-1-1002
推荐答案
尝试这样,
使用视图:
select jointid,max(fitupdetailid),max(weldetaildid) from <yourviewname>
group by jointid
使用SQL:
SELECT
MAX(dbo.fitupdetail.fitupdetailId), dbo.jointId.JointId,
MAX(dbo.weldDetail.WeldDetailId
FROM
dbo.weldDetail
INNER JOIN
dbo.jointId ON dbo.weldDetail.jointid = dbo.jointId.JointId
INNER JOIN
dbo.fitupdetail ON dbo.jointId.JointId = dbo.fitupdetail.jointid
GROUP BY dbo.jointId.JointId
这篇关于在视图SQL Server中返回值的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文