Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用2个WHERE子句将两个select语句合并为一个语句_Sql_Database_Ms Access - Fatal编程技术网

Sql 使用2个WHERE子句将两个select语句合并为一个语句

Sql 使用2个WHERE子句将两个select语句合并为一个语句,sql,database,ms-access,Sql,Database,Ms Access,我正在使用这两个select语句,并希望将它们合并到一个语句中。有人有什么建议吗。但是,问题是我使用的是access,access中没有case子句 SELECT Table_1.Table_Identification_Number, AVG (Table_2.Coulmn-2) AS avg_attribute FROM Table_1 JOIN Table_2 ON Table_1.Table_Identification_Number = Tabl

我正在使用这两个select语句,并希望将它们合并到一个语句中。有人有什么建议吗。但是,问题是我使用的是access,access中没有case子句

SELECT 
     Table_1.Table_Identification_Number,
     AVG (Table_2.Coulmn-2) AS avg_attribute
FROM 
    Table_1 JOIN
    Table_2 ON Table_1.Table_Identification_Number = Table_2.Table_Identification_Number
WHERE
    Table_2.Column-3='1'
GROUP BY 
    Table_1.Table_Identification_Number


SELECT 
     Table_1.Table_Identification_Number,
     AVG (Table_2.Coulmn-2) AS avg_attribute
FROM 
    Table_1 JOIN
    Table_2 ON Table_1.Table_Identification_Number = Table_2.Table_Identification_Number
WHERE
    Table_2.Column-3='2'
GROUP BY 
    Table_1.Table_Identification_Number

您似乎需要条件聚合。如果是,您可以在MS Access中将其表示为:

SELECT t1.Table_Identification_Number,
       AVG(IIF(t2.Column_3 = 1, t2.Column_2, NULL)) as avg_1,
       AVG(IIF(t2.Column_3 = 2, t2.Column_2, NULL)) as avg_2
FROM Table_1 as t1 JOIN
     Table_2 as t2
     ON t1.Table_Identification_Number = t2.Table_Identification_Number
WHERE t2.Column_3 IN (1, 2)
GROUP BY t1.Table_Identification_Number;

请提供样本数据和预期结果。另外,修复数据库标记以确保数据库的准确性。