如果我有以下查询:
SELECT *
FROM Flights
WHERE Flights.From='Rome' OR Flights.To='London';
有没有什么方法可以添加像matched
这样的计算列来标记匹配的字段?
| number | from | to | matched |
|--------|----------|--------|---------|
| 1 | Rome | Munich | "from" |
| 2 | New York | London | "to" |
| 3 | Berlin | London | "to" |
答案 0 :(得分:2)
copy
(SELECT
db_datas
FROM
ir_attachment
WHERE
name='Invoice_SAJ_2016_0964_.pdf')
to '/tmp/Invoice.pdf' (FORMAT "binary");
您可以创建一个模仿WHERE语句逻辑的CASE STATEMENT。
SELECT *,
CASE
WHEN Flights.From='Rome' THEN 'From'
WHEN Flights.To='London' THEN 'To'
END as matched
FROM Flights
WHERE Flights.From='Rome' OR Flights.To='London'
当使用案例陈述时,满足的第一个WHEN条件将是答案,因此如果您的条件满足,并且您希望看到第一个WHEN条件必须寻找这种可能性。
答案 1 :(得分:-1)
SELECT *, (1087 - Flights.Price) as 'mycolumn'
FROM Flights
WHERE Flights.From='Rome' OR Flights.To='London';