SQL-IIF子句在select语句之外?

时间:2016-02-23 21:01:12

标签: mysql sql ms-access ms-access-2010 iif

我正在使用MS Access 2010在SELECT语句中执行一系列UNION。在完成所有这些UNION之后,我需要使用IIF语句添加几个新列(即,基于ch列的值)。但是,我似乎无法找出如何或在何处正确地使用此语法,以便IIF检查最终“unioned”表中的整个列。简单地说,在运行以下语法(对此问题进行修剪和简化)之后,我想在此最终表中根据现有列单元格(例如,'')添加新的变量列(例如,'星号')。等级')包含星号。非常感谢帮助和耐心 - 我只是熟悉SQL的语法原则。

SELECT * FROM(
      SELECT class, teacher, student
      grades2010 AS grades
      WHERE NOT(grades2010 IS NULL OR grades2010="")
      UNION
      SELECT class, teacher, student
      grades2011 AS grades
      WHERE NOT(grades2011 IS NULL OR grades2011="")
      UNION
      SELECT class, teacher, student
          grades2012 AS grades
          WHERE NOT(grades2012 IS NULL OR grades2010="")
)

以下是我想要运行的IIF类型的示例 - 查看“成绩”是否包含星号并创建指标:

IIF(InStr([grades],"*")>0,"YES","NO") AS asterisk

1 个答案:

答案 0 :(得分:1)

所以......你走在正确的轨道上。它看起来像是:

grades

但是...... UNION不是grade子查询中的列,所以这不会起作用。您需要确保将SELECT列添加到子查询中的每个SELECT语句中,以便在主year中对其执行任何操作。

另外值得一提的是,您的架构并不是最好的。您应该只使用import UIKit import CoreGraphics // our Cell class class Cell : UITableViewCell { // cell reuse identifier for table view static let Identifier = "Cell" // the object the cell represents/displays. Could be anything you like var value:AnyObject? { didSet { // update our text field when our cell value is set. self.textField.text = value as? String } } // use a text field to display our contents, since that allows editing and showing the keyboard lazy var textField:UITextField = { let textField = UITextField() self.contentView.addSubview( textField ) return textField }() override func layoutSubviews() { super.layoutSubviews() self.textField.frame = contentView.bounds.insetBy(dx: 20, dy: 4 ) } } // table view data source class class DataSource : NSObject, UITableViewDataSource { var numberOfRows:Int { return items.count } let items = [ "Seoul", "São Paulo", "Bombay", "Jakarta", "Karachi", "Moskva", "Istanbul", "Mexico", "Shanghai", "Tokyo", "New" York, "Bangkok", "Beijing", "Delhi", "London", "Hong Kong", "Cairo", "Tehran", "Bogota", "Bandung", "Tianjin", "Lima", "Rio de Janeiro", "Lahore", "Bogor", "Santiago", "St Petersburg", "Shenyang", "Calcutta", "Wuhan" ] func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return numberOfRows } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier( Cell.Identifier ) as? Cell ?? Cell() cell.value = items[ indexPath.row ] return cell } } class ViewController : UIViewController { override func viewDidLoad() { super.viewDidLoad() // register for notifications when the keyboard appears: NSNotificationCenter.defaultCenter().addObserver( self, selector: "keyboardWillShow:", name: UIKeyboardWillChangeFrameNotification, object: nil) } override func viewDidLayoutSubviews() { tableView.frame = view.bounds } lazy var tableView:UITableView = { let tableView = UITableView() self.view.addSubview( tableView ) tableView.dataSource = self.dataSource tableView.delegate = self return tableView }() lazy var dataSource : DataSource = DataSource() // Handle keyboard frame changes here. // Use the CGRect stored in the notification to determine what part of the screen the keyboard will cover. // Adjust our table view's contentInset and scrollIndicatorInsets properties so that the table view content avoids the part of the screen covered by the keyboard @objc func keyboardWillShow( note:NSNotification ) { // read the CGRect from the notification (if any) if let newFrame = (note.userInfo?[ UIKeyboardFrameEndUserInfoKey ] as? NSValue)?.CGRectValue() { let insets = UIEdgeInsetsMake( 0, 0, newFrame.height, 0 ) tableView.contentInset = insets tableView.scrollIndicatorInsets = insets } } } // need to conform to UITableViewDelegate protocol since we are the table view's delegate extension ViewController : UITableViewDelegate { } // App set up stuff here: @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { lazy var window:UIWindow? = UIWindow() func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { window!.rootViewController = ViewController() window!.makeKeyAndVisible() return true } } 作为列的单个表,而不是每年都有一个表。这将使你不必做这些令人讨厌的事情,而且往往会减慢Union查询。您可以通过创建一个表并使用那里的UNION查询从每个基于表的表中执行INSERT来快速解决这个问题。