# id 是唯一主键 INSERTINTO question (id, type, content) VALUES (#{id}, #{type}, #{content}) ON DUPLICATE KEY UPDATE content=#{content}
插入时先使用条件查询,满足条件时才插入,不满足条件就不进行插入
1 2 3 4 5 6 7 8
# 根据条件查询,满足条件时才插入 INSERTINTO paper_knowledge_point_relation(paper_id, knowledge_point_id, tenant_code) SELECT #{paperId}, #{knowledgePointId}, #{tenantCode} FROM dual WHERENOTEXISTS( SELECT1FROM paper_knowledge_point_relation WHERE paper_id=#{paperId} AND knowledge_point_id=#{knowledgePointId} AND tenant_code=#{tenantCode} )
查询更新
查询的结果作为临时表,更新知识点下的题目数量
1 2 3
UPDATE question_knowledge_point qkp JOIN (SELECT knowledge_point_id AS id, COUNT(id) AS count FROM question GROUPBY knowledge_point_id) AS t ON qkp.id=t.id SET qkp.count=t.count
使用了子查询
左连接
查询所有题目及它的选项
1 2 3
SELECT q.id, q.content, qo.id, qo.content FROM question q LEFTJOIN question_option qo ON q.id=qo.question_id
内连接
内连接 JOIN 和 WHERE 等价,查询所有有选项的题目
1 2 3 4 5 6 7
SELECT q.id, q.content, qo.id, qo.content FROM question q JOIN question_option qo ON q.id=qo.question_id
SELECT q.id, q.content, qo.id, qo.content FROM question q, question_option qo WHERE q.id=qo.question_id
CREATEVIEW view_paper_knowledge_point ASSELECT pkpr.paper_id AS paper_id, kp.knowledge_point_id AS knowledge_point_id, kp.name AS name, kp.tenant_code AS tenant_code FROM paper_knowledge_point_relation pkpr LEFTJOIN knowledge_point kp ON pkpr.knowledge_point_id = kp.knowledge_point_id WHERE kp.is_deleted=0;
网上还看到说直接修改 user 表中 User root 的 Host 为 **%**,最好别这么干,不小心会哭的:
1 2 3 4
USE mysql; SELECTuser, host FROMuser; UPDATE userSET host='%'WHEREuser='root'; FLUSH PRIVILEGES;
按照上面的修改 host 为 % 后外网可以访问了,但是本地却访问出错:
1 2 3
mysql -uroot -p 提示 Access denied for user 'root'@'localhost' (using password: YES) when trying
可用按下面的方式补救:
1 2 3 4 5 6 7 8 9 10
1. 启动 mysqld_safe mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 2. 登陆修改 mysql -u root mysql use mysql UPDATE user SET host='localhost' WHERE user='root'; FLUSH PRIVILEGES; quit
zTree 不支持 jQuery ui 的拖拽操作,因为 drop 事件阻止了 mouse up 事件的冒泡以致 zTree 不能调用 onMouseUp 的回调函数。为了拖拽普通的 element 到 zTree 上,需要自己实现拖拽功能,Drag With Other DOMs 演示了具体的实现,但是代码太多,不易于理解,这里把拖拽相关的核心代码提取出来,就能快速的理解拖拽的实现。