本文介绍了如何通过在T-Sql中传递倍数值来获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表有2列,即PlanId和RiderId,格式如下 -
查询是 - 我想传递多个riderid,我想得到 PlanId
基于多个 RiderId
。
在这种情况下,我将传递 327,329,330,326,355
。
但在 PlanId
列中有327次可用 356349
和 356347
但在这里我只想要一个 PlanId
,这是 356349
,因为它包含组合值。我是怎么做到这一点的。
Hi,
I have a table which has 2 columns namely PlanId and RiderId in below format-
Query is- I want pass multiple riderid and i want to get PlanId
on the base of multiple RiderId
.
In this case i will pass 327,329,330,326,355
.
But 327 available in 2 times in PlanId
column having 356349
and 356347
but here i want only one PlanId
which is 356349
, because it hold combination values. How i accomplish this.
PlanId RiderId
===============
356348 330
356348 355
356348 327
356348 329
356349 327
356349 329
356349 330
356349 326
356349 355
推荐答案
SELECT
YourTable.PlanId
,YourTable.RiderId
FROM
YourTable
GROUP BY
YourTable.PlanId,
YourTable.RiderId
HAVING
YourTable.RiderId IN (--your inputs here)
--Example:
--YourTable.RiderId IN (327,329,330,326,355)
希望有帮助
Hope it helps
CREATE PROCEDURE GetPlanIDByRiderID
@riderids NVARCHAR(1000)
--example input: '321, 322, 333'
AS
SELECT PlanId, RiderId
FROM YourTable
WHERE RiderId IN (@riderids)
ORDER BY PlanId, RiderId
GO
这篇关于如何通过在T-Sql中传递倍数值来获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!