在我的客户表中,有一行称为* inactive_status *,它始终设置为'Active'。这是除非* is_paid *(位于Billing_Info表)设置为0.我需要使用更新命令,但无法弄清楚。以下是我迄今为止:SQL从一个表更新到另一个表,没有公共数据
UPDATE Customer
SET inactive_status = 'INACTIVE'
WHERE
(SELECT is_paid
FROM Billing_Info
WHERE billing_info.is_paid = 0);
DDL:
CREATE TABLE billing_info (
billing_info_id INT,
bill_day_id INT,
is_past_due NUMBER(1,0) NOT NULL,
date_last_paid DATE,
is_paid_this_month NUMBER(1,0) NOT NULL,
paid_amount DECIMAL(6,2) NOT NULL,
bill_amount DECIMAL(6,2) NOT NULL,
CONSTRAINT billing_info_id_pk PRIMARY KEY(billing_info_id));
CREATE TABLE customer (
customer_id INT,
join_date DATE NOT NULL,
billing_info_id INT NOT NULL,
inactive_status VARCHAR2(25),
contact_info_id INT NOT NULL,
CONSTRAINT customer_id_pk PRIMARY KEY (customer_id));
有什么建议?
在您的billing_info表中应该有一个customer_id。否则,您如何知道哪些Cusomters应该更新? – CoffeeMonster 2013-02-16 02:49:39
有,但是customer_id与inactive_status没有任何关系。我正在使用别人的工作,不能回去改变任何东西。基本上每个客户都有储存在多个表格中的信息,而我正在处理的数据现在没有链接,但需要链接。 – Comicstorm 2013-02-16 03:21:32
请发布您的DDL(创建表语句)'Customer'和'Billing_Info'两个表。 – peterm 2013-02-16 03:42:16