找到4个响应的值 [英] Finding the values for 4 RESPONSES
问题描述
MS SQL SERVER 2008
DECLARE @Request AS TABLE(响应VARCHAR(30),ATTRIBS DECIMAL(18,2))
INSERT INTO @Request VALUES('HAPPY',100)
INSERT INTO @Request VALUES('SATISFIED',75)
INSERT INTO @Request VALUES('NEUTRAL',50)
INSERT INTO @Request VALUES('UNHAPPY',25)
INSERT INTO @Request VALUES('NO-RESPONSE', NULL)
表回复
------- ---------------
BRN_NAME
RESPONSE1
RESPONSE
RESPONSE3
RESPONSE4
SELECT A.BRN_NAME,
A.RESPONSE1,
A.RESPONSE2,
A.回复3,
A.RESPONSE4
来自回应A
LEFT JOIN @Request C ON A.RESPONSE1 = C.RESPONSE
我有回复列表
A.RESPONSE1,
A.RESPONSE2,
A.RESPONSE3,
A.RESPONSE4
我需要通过链接到查找表来获取值 @Request
如何完成Select语句以获得相当于
的值A.RESPONSE1,
A.RESPONSE2,
A. RESPONSE3,
A.RESPONSE4
我的尝试:
这是一个正在建设中的程序段
MS SQL SERVER 2008
DECLARE @Request AS TABLE (RESPONSE VARCHAR (30), ATTRIBS DECIMAL(18,2))
INSERT INTO @Request VALUES('HAPPY' ,100)
INSERT INTO @Request VALUES('SATISFIED' , 75)
INSERT INTO @Request VALUES('NEUTRAL' , 50)
INSERT INTO @Request VALUES('UNHAPPY' , 25)
INSERT INTO @Request VALUES('NO-RESPONSE', NULL)
TABLE RESPONSE
----------------------
BRN_NAME
RESPONSE1
RESPONSE2
RESPONSE3
RESPONSE4
SELECT A.BRN_NAME ,
A.RESPONSE1,
A.RESPONSE2,
A.RESPONSE3,
A.RESPONSE4
FROM RESPONSE A
LEFT JOIN @Request C ON A.RESPONSE1 =C.RESPONSE
I have a list of responses
A.RESPONSE1,
A.RESPONSE2,
A.RESPONSE3,
A.RESPONSE4
which I need to get their values by linking to the Lookup table @Request
How do I complete the Select Statement to get the values equivalent of
A.RESPONSE1,
A.RESPONSE2,
A.RESPONSE3,
A.RESPONSE4
What I have tried:
This is a program segment under construction
推荐答案
当我建议你昨天创建一个表时:根据计数计算平均值 [ ^ ]我没有建议表变量:make it a a 永久表,就像你现有的表一样。
然后 - 按照我的建议 - 使用JOIN:
When I suggested that you create a table yesterday: Computing the averages based on counts[^] I didn't suggest a table variable: make it a "permanent" table, just like your existing table is.
Then - as I suggested - use a JOIN:
SELECT a.Brn_name, b.Attribs, c.Attribs, d.Attribs, e.Attribs
FROM Response a
JOIN Requests b ON a.RESPONSE1 = b.Response
JOIN Requests c ON a.RESPONSE2 = c.Response
JOIN Requests d ON a.RESPONSE3 = d.Response
JOIN Requests e ON a.RESPONSE4 = e.Response
这篇关于找到4个响应的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!