如何在sql语句的where子句中设置任何标志?

时间:2015-06-30 04:38:29

标签: sql oracle

我编写了以下SQL查询,以便使用以下条件检索值。现在,如果我想在任何比较结束时设置一个标志我该怎么做呢?

package main

import (
     "encoding/json"
     "fmt"
)


func main() {
    j := []byte(`["contig", "32", {"a":[33,41,35], "b":[44,34,42]}]`)

    var entries []json.RawMessage
    err := json.Unmarshal(j, &entries)
    if err != nil {
        fmt.Println(err)
    }

    var contig string
    var num string
    var obj struct {
        A []int `json:"a"`
        B []int `json:"b"`
    }

    err = json.Unmarshal(entries[0], &contig)
    err = json.Unmarshal(entries[1], &num)
    err = json.Unmarshal(entries[2], &obj)

    fmt.Println(contig)
    fmt.Println(num)
    fmt.Println(obj)
}

现在在每个'或'条件结束时,我需要设置一个标志。就像第一个条件为真,那么我想将标志设置为1,否则为第二个条件,我想将它设置为2.依此类推。

1 个答案:

答案 0 :(得分:0)

你可以像这样输出“case when”条件

select x.transaction_id 
case when to_char(x.transaction_date)<>to_char(y.transaction_date) then 1 else
case when to_char(x.business_date)<>to_char(y.business_date) then 2 else
case when to_char(x.transaction_value_date) <> to_char(y.transaction_value_date) then 3 else
case when  x.transaction_type<> y.transaction_type then 4 else
case when  x.customer_id <> y.customer_id then 5 else 6 end end end end end
as columnname
from nsbt_atm_trx_log_13763 x inner join  nsbt_host_trx_log_13763 y on x.transaction_id = y.transaction_id
 where  to_char(x.transaction_date)<>to_char(y.transaction_date) or
 to_char(x.business_date)<>to_char(y.business_date) or
 to_char(x.transaction_value_date) <> to_char(y.transaction_value_date) or
 x.transaction_type<> y.transaction_type or
 x.account_number <> y.account_number or
 x.customer_id <> y.customer_id or
 x.transaction_amount <> y.transaction_amount;