我的代码表包含以下数据
_________
dbo.Codes
_________
AXV
VHT
VTY
和包含以下数据的电子邮件表
_________
dbo.email
_________
x@gmail.com
y@gmail.com
z@gmail.com
我希望能够使用以下输出水平连接这两个表。
__________
dbo.output
__________
AXV x@gmail.com
VHT y@gmail.com
VTY z@gmail.com
有没有办法获得所需的输出?
编辑#1 这两个表都包含唯一代码和唯一的电子邮件地址
答案 0 :(得分:2)
假设这是SQLServer,请尝试:
; with
c as (select codes, row_number() over (order by codes) r from codes),
e as (select email, row_number() over (order by email) r from email)
select codes, email
from c join e on c.r = e.r
order by c.r
答案 1 :(得分:1)
你可以这样做。
select c.Codes , e.email
from CodesTable c, emailTable e
where c.rownum = e.rownum;
答案 2 :(得分:0)
SELECT email, code
FROM
(SELECT email, ROW_NUMBER() OVER(ORDER BY email) AS RowNum FROM email) AS T1
OUTER JOIN
(SELECT code, ROW_NUMBER() OVER(ORDER BY code) AS RowNum FROM codes) AS T2
ON T2.RowNum = T1.RowNum
ORDER BY COALESCE(T1.RowNum, T2.RowNum)
答案 3 :(得分:0)
创建新表
创建表测试( code varchar(32), email varchar(32) 唯一的(代码), 唯一的(电子邮件) );
执行此sql的结果
选择'插入测试(代码,电子邮件)值('''+代码+''','''+电子邮件+''');'来自test1,test2
所有sqls都不会被成功执行,但是表格将按顺序填充 当您选择测试表时,您将获得所需的