SELECT t1.organization_id, t1.organization_name, SUM( t2.jl_amount ) yfSjAmount, SUM( t2.sj_amount ) yfJlAmount, SUM( t3.money ) yfSectionAmount, SUM( t3.mileage ) yfSectionLength FROM main_project t1 LEFT JOIN mat_approval_project t2 ON t2.main_id = t1.id LEFT JOIN mat_project_pavement_approval t3 ON t3.project_id = t2.id WHERE t1.project_general_name = '预防性养护' AND t1.project_category_name = '路面工程' AND t1.process_status = '100' AND t1.organization_id = 'b3f029fa-62ab-476e-9876-b87ce69c41c5' AND t1.project_year = '2023' SQL统计错误,请修改
时间: 2024-03-13 16:44:10 浏览: 87
这条SQL语句缺少结束符号,可以在语句末尾添加分号(;)来解决。
完整的SQL语句应该是:
```
SELECT t1.organization_id, t1.organization_name, SUM(t2.jl_amount) yfSjAmount, SUM(t2.sj_amount) yfJlAmount, SUM(t3.money) yfSectionAmount, SUM(t3.mileage) yfSectionLength
FROM main_project t1
LEFT JOIN mat_approval_project t2 ON t2.main_id = t1.id
LEFT JOIN mat_project_pavement_approval t3 ON t3.project_id = t2.id
WHERE t1.project_general_name = '预防性养护'
AND t1.project_category_name = '路面工程'
AND t1.process_status = '100'
AND t1.organization_id = 'b3f029fa-62ab-476e-9876-b87ce69c41c5'
AND t1.project_year = '2023';
```
相关问题
SELECT t1.organization_id, t1.organization_name, t1.road_name, SUM( t2.sj_amount ) xfSjAmount, SUM( t2.jl_amount ) xfJlAmount, SUM( t3.xfGeneralSectionAmount ) xfGeneralSectionAmount, SUM( t3.xfGeneralSectionLength ) xfGeneralSectionLength FROM `main_project` t1 LEFT JOIN mat_approval_project t2 ON t2.main_id = t1.id LEFT JOIN ( SELECT project_id, data_type, SUM( money ) xfGeneralSectionAmount, SUM( mileage ) xfGeneralSectionLength FROM mat_project_pavement_approval GROUP BY project_id ) t3 ON t3.project_id = t2.id WHERE t1.project_general_name = '修复性养护' AND t1.project_category_name = '路面工程' AND t1.process_status = '100' AND t3.data_type = '1' AND t1.road_name = '常祁高速' AND t1.project_year = '2023' 这条sql中t1.road_name多条数据只会展示一个,导致根据t1.road_name查询不到数据
这个问题的原因可能是使用了`LEFT JOIN`,导致t1表中的多个记录与t2和t3表中的记录进行了匹配。如果t1表中有多个记录的`t1.road_name`值相同,那么在`SELECT`语句中使用`SUM`函数对t2和t3表中的记录进行了合并,使得最终查询结果中只有一个记录。这可能导致你根据`t1.road_name`无法查到完整的数据。
为了解决这个问题,你可以考虑在`SELECT`语句中增加`t1.road_name`字段,并在`GROUP BY`子句中包含该字段,以确保t1表中的每个记录都能够被正确匹配和展示。例如:
```
SELECT
t1.organization_id,
t1.organization_name,
t1.road_name,
SUM(t2.sj_amount) AS xfSjAmount,
SUM(t2.jl_amount) AS xfJlAmount,
SUM(t3.xfGeneralSectionAmount) AS xfGeneralSectionAmount,
SUM(t3.xfGeneralSectionLength) AS xfGeneralSectionLength
FROM
main_project t1
LEFT JOIN mat_approval_project t2 ON t2.main_id = t1.id
LEFT JOIN (
SELECT
project_id,
data_type,
SUM(money) AS xfGeneralSectionAmount,
SUM(mileage) AS xfGeneralSectionLength
FROM
mat_project_pavement_approval
GROUP BY
project_id
) t3 ON t3.project_id = t2.id
WHERE
t1.project_general_name = '修复性养护'
AND t1.project_category_name = '路面工程'
AND t1.process_status = '100'
AND t3.data_type = '1'
AND t1.road_name = '常祁高速'
AND t1.project_year = '2023'
GROUP BY
t1.organization_id,
t1.organization_name,
t1.road_name;
```
这样,就可以确保每个`t1.road_name`值都能够正确地展示在查询结果中。
前面是INSERT INTO amount_store_rank SELECT t1.store_id,t2.store_name,sum(t1.goods_price) as amount_total FROM kafka_source t1 left join table_store_info as t2 on t1.store_id=t2.store_id WHERE t1.shopping_type = 'buy' group BY t1.store_id,t2.store_name;
根据你提供的完整SQL语句,我发现可能是SQL语句中的某个字符串常量未被正确地闭合引号,导致了语法错误。请检查SQL语句中所有的字符串常量,确保它们都被正确地闭合引号。
同时,你也可以检查SQL语句的其他部分,看看是否有其他语法错误或者拼写错误。如果需要更多帮助,请提供更多上下文信息,以便我更好地理解你的问题。
阅读全文