将两个IN语句合并为一个子句?

时间:2016-02-13 02:59:49

标签: sql

WHERE
    E.CNO IN
    (
    SELECT
        CNO
    FROM
        COURSE
    WHERE
        LOWER(CNAME) LIKE LOWER('%WORLD%')
    AND
        LOWER(CNAME) LIKE LOWER('%HISTORY%')
    )
AND
    C.DNAME IN
    (
    SELECT
        DNAME
    FROM
        COURSE
    WHERE
        LOWER(CNAME) LIKE LOWER('%WORLD%')
    AND
        LOWER(CNAME) LIKE LOWER('%HISTORY%')
    );

这给了我正在寻找的结果,但我有点强迫症,并希望能够在可能的情况下缩短它。贝娄是我想做的,但我不确定操作员是否会工作。

WHERE
    E.CNO, C.DNAME IN
    (
    SELECT
        CNO,
        DNAME
    FROM
        COURSE
    WHERE
        LOWER(CNAME) LIKE LOWER('%WORLD%')
    AND
        LOWER(CNAME) LIKE LOWER('%HISTORY%')
    );

1 个答案:

答案 0 :(得分:2)

某些数据库支持import UIKit class ViewController: UIViewController { @IBOutlet weak var scoreLabel: UILabel! var points: Int = 0 var tickCount=0 var spawnRate=100 // Spawn every 10 seconds to start with var spawnTimer:NSTimer! override func viewDidLoad() { super.viewDidLoad() self.tickCount=self.spawnRate self.spawnTimer=NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: Selector("tick"), userInfo: nil, repeats: true) } func tick() { if (--tickCount == 0) { self.spawnEnemy() self.spawnRate=spawnRate - 2 // Change this to determine how quickly the spawn rate increases self.tickCount=self.spawnRate } } 子句中的多个列。但是,您可能会发现可以使用injoin重写它。以下是exists

的示例
exists

或者您可以使用where exists ( select 1 from course where e.cno = course.cno and c.dname = course.dname and lower(c.cname) like lower('%WORLD%') and lower(c.cname) like lower('%HISTORY%') )

join

那里不需要子查询。