从一个简单的查询开始……</p>
SELECT UserID AS ‘User ID’, UserName AS ‘User Name’ FROM tblUsers
OUTPUT:
User ID User Name
1 Joe
2 Bob
3 Larry
但随后我需要运行以用户 ID 作为输入的存储过程:
GetUsersLastTransaction(pID_User)
谁的 SQL 可以是任何东西 ( SELECT <whatever> WHERE <whatever> = UserID
)
GetUsersAccountBalance(pID_User)
再次,谁的 SQL 可以是任何东西 ( SELECT <whatever> WHERE <whatever> = UserID
)
那么我怎样才能进行查询,给我一个像这样的数据表
OUTPUT:
User ID User Name Last Transaction Account Balance
1 Joe Transaction xyz 1000
2 Bob Transaction pdq 1500
3 Larry Transaction abc 1110
SELECT UserID AS ‘User ID’, UserName AS ‘User Name’, (
SELECT <whatever>
WHERE <whatever> = ????
) AS ‘Last Transaction’, (
SELECT <whatever>
WHERE <whatever> = ????
) AS ‘Account Balance’
那么,如何使用子查询的 where 子句 (????) 中第一列(“用户 ID”)中的值,并使其适用于每一行?