如何使用多个键连接表

时间:2017-09-01 20:03:54

标签: sql sql-server join

我正在尝试在一个视图中找到一种方法来连接下面的两个表,其中字符和级别都被组合为一个键ID,并且该级别的该字符的统计信息被展开。我可以在视图中执行此操作,还是需要废弃单独的表?

表1:

const isPresent = sharing.modal.isPresent()
if (isPresent) {
    sharing.modalAcceptButton.click()
} //THIS FAILS WHEN MODAL NOT PRESENT

const isPresent = sharing.modal.isPresent()
isPresent.then(result => {
    if (result) {
        sharing.modalAcceptButton.click()
    } //THIS FAILS WHEN MODAL NOT PRESENT
})

const isPresent = sharing.modal.isPresent()
const isDisplayed = sharing.modal.isDisplayed()
if (isPresent && isDisplayed) {
    sharing.modalAcceptButton.click()
} //THIS FAILS WHEN MODAL NOT PRESENT

// THIS ALSO FAILS
const isPresent = browser.isElementPresent(sharing.modal.getWebElement())
isPresent.then(present => {
    if (present) {
                    sharing.modalAcceptButton.click()
                    const sharedWithAfter = sharing.sharedUsers.count()
                    Promise.all([sharedWithBefore, sharedWithAfter]).then(results => {
                        expect(results[0] != results[1]).toBe(true)
                    })
                } else {
                    const sharedWithAfter = sharing.sharedUsers.count()
                    Promise.all([sharedWithBefore, sharedWithAfter]).then(results => {
                        expect(results[0] != results[1]).toBe(true)
                    })
                }
            })

// This is likewise failing
                const isPresent = browser.isElementPresent(sharing.modal.getWebElement())
            isPresent.then(present => {
                try {
                    if (present) {
                        sharing.modalAcceptButton.click()
                        const sharedWithAfter = sharing.sharedUsers.count()
                        Promise.all([sharedWithBefore, sharedWithAfter]).then(results => {
                            expect(results[0] != results[1]).toBe(true)
                        })
                    }
                } catch (NoSuchElementError) {
                    console.log('The Modal is not present continuing')
                    const sharedWithAfter = sharing.sharedUsers.count()
                    Promise.all([sharedWithBefore, sharedWithAfter]).then(results => {
                        expect(results[0] != results[1]).toBe(true)
                    })

                }
            })

表2:

Character   | Level | Attack Value|
Character A | 1     | 2
Character A | 2     | 2
Character B | 1     | 3
Character B | 2     | 4

期望的结果:

Character   | Level | Defense Value|
Character A | 1     | 4
Character A | 2     | 5
Character B | 1     | 1
Character B | 2     | 2

2 个答案:

答案 0 :(得分:2)

使用字符和级别

加入表1和表2
SELECT t1.character,
       t1.level,
       t2.[defense value],
       t1.[attack value]
  FROM table1 t1
  JOIN table2 t2
    ON t1.character = t2.character
   AND t1.level = t2.level

答案 1 :(得分:2)

您可以简单地通过多个值加入

CREATE VIEW view_name AS
SELECT 
   t1.Character, 
   t1.Level, 
   t2.`attack value`, 
   t1.`defense value`
FROM 
   table1 t1 
JOIN table2 t2 ON 
     t1.Character = t2.Character 
     AND t1.Level = t2.Level
相关问题