2

我有一个记录表单提交的表。对于表单的每次提交,都有以下变量:

userid
record
accountName
accountNumber

当用户提交表单时,表格中会填充record每个行项目的值。换句话说,这些值通常都由record值链接。我正在尝试用户INNER JOIN将结果过滤到显示userid,accountNameaccountNumber列的表中。我非常接近这个命令:

SELECT t1.value AS number, t2.value AS name, t3.value AS userid
FROM mytable AS t1
INNER JOIN mytable AS t3
INNER JOIN mytable AS t2 ON t1.record = t2.record
WHERE t1.name = 'addAccountNumber'
AND t2.name = 'addAccountName'
AND t3.name = 'userid'

唯一的问题是结果不限于每个条目一个。桌子上似乎显示了多个实例。

我认为需要围绕WHERE声明的部分进行一些编辑。在我看来,结果并没有根据名称值来过滤结果。关于如何解决这个问题的任何建议?


更新:

我应该补充一点,当我在调用中只包含两行时,我确实得到了正确的过滤结果,如下所示:

SELECT t1.value AS accountNumber, t2.value AS accountName
FROM mytable AS t1
INNER JOIN mytable AS t2
ON t1.record=t2.record WHERE t1.name='addAccountNumber' AND t2.name='addAccountName'

认为这可能有助于显示我来自哪里。所以,一般来说,这与添加userid给我带来麻烦的变量有关

4

1 回答 1

2

我很难理解你需要什么,但也许就是这样。

SELECT t1.value AS number, t2.value AS name, t3.value AS userid

FROM mytable AS t1

INNER JOIN mytable AS t3 ON t1.record = t3.record

INNER JOIN mytable AS t2 ON t1.record = t2.record

WHERE t1.name = 'addAccountNumber'

AND t2.name = 'addAccountName'

AND t3.name = 'userid'
于 2013-03-26T22:08:46.077 回答