SqLite composite从Select语句中选择

时间:2014-04-08 13:29:13

标签: sqlite

如何从sqlite中的另一个select执行复合select语句?是否可以使用select?

中的计算列在WHERE子句中添加条件

我有以下工作声明

SELECT detection_id,
      evalround_id,
      min(detection.posright, labelgt.posright) - max(detection.posleft, labelgt.posleft) + 1 
        AS overlap_width
FROM detection, labelgt
WHERE 
      labelgt.timestamp = detection.timestamp 

我想在计算的'overlap_width'

上添加条件
 AND overlap_width > 0 

不幸以错误结束'执行查询时出错:没有这样的列:overlap_width'。

我尝试创建一个复合语句,

SELECT
    *
    FROM
        (
         SELECT  detection_id,
              evalround_id,
              min(detection.posright, labelgt.posright) - max(detection.posleft, labelgt.posleft) + 1 
                AS overlap_width
            -- overlap_width * overlap_height AS overlap_area
        FROM detection, labelgt
        WHERE 
                labelgt.timestamp = detection.timestamp 
        ) AS IT
    WHERE
        IT.overlap_width > 0

在执行查询时出现'错误:没有这样的列:detection.posleft'。但是表格中有一个有效的列检测.posleft。

1 个答案:

答案 0 :(得分:0)

SQLite支持它,你可以在你的内部列上有条件。即。

SELECT * FROM (select min(b.cold1-c.col2) as tid, *  from table1 b , table2 c )   where tid =  -538