如何使用concat("操作名称",'仅用于空格',(MySQL查询从另一个表中选择)?
尝试这样:
INSERT INTO log
set operation = "create",
detail= Concat("Creating new Data", ' ', (SELECT name from employees where employees.id = new.employ_id)),
time = NOW()
但是我在第三个参数中得到了一个错误...
但如果我这样试过:
INSERT INTO log
set operation = "create",
detail= SELECT name from employees where employees.id = new.employ_id,
time = NOW()
如果我在表格中创建新数据,员工姓名可以显示
如何解决这个问题?帮助请
感谢
答案 0 :(得分:0)
我认为你应该写这样的逻辑:
INSERT INTO log(operation, detail, time)
SELECT 'create',
concat('Creating new Data', ' ', e.name),
NOW()
FROM employees e
WHERE e.id = new.employ_id;
我不确定这是否能解决您的错误 - 您还没有明确说明错误。但是,这是编写查询的更自然的方式。