当主键匹配且没有活动"Y"插入记录的行时,我想执行以下操作.这可能吗?
我试过这个:
-- Merge statement
MERGE INTO table1 AS DST
USING table2 AS SRC
ON (SRC.Code = DST.Code)
--Existing records updated if data changes
WHEN MATCHED
AND IF NOT EXISTS (WHERE active='Y' FROM table1 )
THEN
INSERT INTO table1 (colum)
SELECT value
+-------+-------------+--------+
| Code | description | Active |
+-------+-------------+--------+
| AB | just | |
| | something | No |
+-------+-------------+--------+
Run Code Online (Sandbox Code Playgroud)
只有当没有相同代码的活动记录时,我才想插入记录.新记录看起来像这样
+-------+-------------+--------+
| Code | description | Active |
+-------+-------------+--------+
| AB | something | | …Run Code Online (Sandbox Code Playgroud) 我有一个代码,当我在页面上使用它时,但我试图使这个功能.我无法让它工作,似乎变量$ customer和$ system没有被发送到代码.即使我在Raw中键入它.有什么想法错了吗?$ Customer是客户的名称,$ system可以是'Source'或'Target'.
function status_total($customer, $system){
$sql_customer = "SELECT * FROM `Customer` WHERE Cust_Name = '$customer' LIMIT 0,1";
$customer_selection = mysqli_query($conn,$sql_customer);
$customer_row = mysqli_fetch_assoc($customer_selection);
$env_lines = $customer_row["Env_Lines"];
$cust_id = $customer_row["Cust_ID"];
$sql_last_records = "SELECT * FROM $system WHERE Cust_ID = $cust_id ORDER BY Time DESC LIMIT $env_lines";
$record_selection = mysqli_query($conn, $sql_last_records);
$result = mysqli_fetch_all($record_selection, MYSQLI_ASSOC);
$states = array_column($result, "Stat");
if($states == array_fill(0, count($states), "Run")) {
echo "Success";
} else
echo "Fail";
}
Run Code Online (Sandbox Code Playgroud)