mysql - 错误代码:1054 'where 子句'中的未知列'billId'
问题描述
尽管有很多与此类似的问题。它与其他人完全不同。而且我无法找到纠正确切错误的方法。这就是为什么在这里发布它。
我正在编写一个查询,我需要使用一个 ID 删除多个表上的条目。
我有estimate_id。我想删除 bill 表还有 bill_details 表。在 bill_details tbl 中存储了 bill_id。所以我写了一个查询来从 bill tbl 中进行选择。但是在 where 子句中使用它时最终出错。
存储过程在这里:
CREATE DEFINER=`root`@`localhost` PROCEDURE `delete_by_estimation_no`(in_estimation_id int)
BEGIN
SET SQL_SAFE_UPDATES = 0;
select (id)projId from projects WHERE estimation_no=in_estimation_id;
DELETE FROM projects WHERE estimation_no=in_estimation_id;
DELETE FROM estimation WHERE id=in_estimation_id;
DELETE FROM estimation_details WHERE estimation_id=in_estimation_id;
select (id)billId from bill where estimation=in_estimation_id;
DELETE FROM bill WHERE estimation=in_estimation_id;
DELETE FROM bill_details WHERE bill_id=billId;
select (id)invoiceId from invoice where estimation=in_estimation_id;
DELETE FROM invoice WHERE estimation_no=in_estimation_id;
DELETE FROM invoice_details WHERE invoice_id=invoiceId;
select (id)crId from change_request where project_id=projId;
DELETE FROM change_request WHERE project_id=projId;
DELETE FROM change_request_details WHERE cr_id=crId;
END
我收到这个错误。
错误代码:1054 'where 子句'中的未知列'billId'
[![Bill][1]][1]
解决方案
bill_details 中没有 billId 列,但您可以通过查询从两个表中删除
DELETE bill, bill_details
FROM bill
INNER JOIN bill_details ON bill.id = bill_details.bill_id
(假设连接键是 id 和 bill_id)
推荐阅读
- spss - 运行 MANOVA,其中 Pillai's/Wilks 不显着,但其中一个 DV 在我的受试者间效应输出表中非常重要
- camunda - 如何在 DMN 中定义 Decison 表
- powerbi - 将公式重新应用于 power bi 中相同类型的新源
- laravel - 将我的 Laravel 代码从一台服务器移动到另一台服务器后,推送通知不起作用
- javascript - 如何修复 johnny 5 安装错误?
- sql - 在 SQL 中获取与一个对象相关的所有对象
- angular - Angular Mat-table DataSource 值在更新状态时更改
- java - Android:使用自定义 ClassLoader 导致的异常
- javascript - 什么是断言方法?
- sorting - 如何获取将在 Rust 中对向量进行排序的索引?