多列

时间:2016-02-26 16:35:57

标签: sql

我正在尝试从单个行创建多个列,在sql developer中连接两个表。我总是得到太多的价值观"错误 表一 EIM_PR_IB_LATESTES ROEL_ID客户ID 010427DF00281 1 5007175 010427DF00281 8 5007175 010427DF00281 21 5007175 180015309 7 5002769 180015309 10 6054515 010427DF00282 3 5019547 010427DF00282 7 6032145 010427DF00283 3 6032145 010427DF00283 4 5002304

表2-EIM_PARTY TABLE客户ID customer_name 6738986 Henry Schein英国控股有限公司6738988 Bristol Babcock Ltd. 6739000直接汽车金融服务有限公司6739022 Capita Hartshead Benefit Consultants Ltd. 6739024 Danfoss Ltd. 6739026 Assurant Solutions UK 6739028 West Yorkshire Fire& ;救援服务6739037 Suffolk Fire&救援服务6739042 North Wales Police 6739051 Weymouth& Portland Borough Council 6739055 Mqsoftware Ltd. 6739060 Shrewsbury Sixth Form College 6739062 Cadbury Sixth Form College

我需要多个customer_id列和多个customer_name列

AS example-system_serial_number客户ID经销商resellertwo客户ID AS MAINTAINER 123 1已售出已安装1已安装234 2已售出已安装2已安装

SELECT *
FROM (
    SELECT system_serial_number,
        (
            SELECT b.customer_id,
                d.customer_name
            FROM eim_pr_ib_latest b,
                eim_party d
            WHERE b.customer_id = d.customer_id
                AND b.role_id = '21'
            ) AS reseller,
        (
            SELECT b.customer_id,
                d.customer_name
            FROM eim_pr_ib_latest b,
                eim_party c
            WHERE b.customer_id = c.customer_id
                AND b.role_id = '3'
            ) AS resellertwo
    FROM eim_pr_ib_latest b
    WHERE b.role_id('21', '3')
    )
ORDER BY system_serial_number

预期结果

system_serial_number    customer id reseller    resellertwo
123 1   sold    installed
234 2   sold    installed

0 个答案:

没有答案