简体   繁体   English

SQLite Query使用嵌套的SELECT

[英]SQLite Query using nested SELECT

I'm trying to select cpu_time from the db, but the time must correspond with a few other criteria - ie build_version, test_letter, design_index, multi_thread, and test_index 我正在尝试从db中选择cpu_time,但时间必须与其他一些标准相对应 - 即build_version,test_letter,design_index,multi_thread和test_index

What I thought would work was (the inner SELECT DISTINCT statement works on its own): 我认为可行的是(内部SELECT DISTINCT语句自己工作):

set query [db eval \
    {SELECT DISTINCT cpu_time WHERE cpu_time IN 
            (SELECT DISTINCT mgc_version, test_type_letter, design_index, 
                             test_index, cpu_time, multi_thread 
                    FROM TestExecutions WHERE test_type_letter
                    BETWEEN $testletter AND $testletter)}]

***Note - this is giving me a "no such column: cpu_time" error ***注意 - 这给了我一个“没有这样的列:cpu_time”错误

where my first SELECT would pull all items from a distinct return. 我的第一个SELECT将从不同的返回中提取所有项目。 Then, from each return, I wanted to ONLY use the cpu_time, for each type of $testletter. 然后,从每次返回,我想只为每种类型的$ testletter使用cpu_time。

This is for generating CSV files that only have the cpu_time. 这用于生成仅具有cpu_time的CSV文件。 Is it obvious what I'm getting wrong? 我明白错了什么?

Thank you! 谢谢!

You should always use WHERE xxx IN (SELECT xxx FROM ...) , instead of selecting multiple items in the inner select. 您应该始终使用WHERE xxx IN (SELECT xxx FROM ...) ,而不是在内部选择中选择多个项目。 You can add those in the outer select though, for example: 您可以在外部选择中添加这些,例如:

SELECT DISTINCT 
    mgc_version, 
    test_type_letter, 
    design_index, 
    test_index, 
    cpu_time, 
    multi_thread 
FROM TestExecutions
WHERE cpu_time IN 
(
    SELECT DISTINCT cpu_time 
    FROM TestExecutions 
    WHERE test_type_letter BETWEEN $testletter AND $testletter
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM