十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这篇文章主要为大家展示了“MySQL中入门语句的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“mysql中入门语句的示例分析”这篇文章吧。
成都地区优秀IDC服务器托管提供商(创新互联建站).为客户提供专业的遂宁联通机房,四川各地服务器托管,遂宁联通机房、多线服务器托管.托管咨询专线:18982081108
LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行。
(业务需求:从一张表查询出来的数据要关联到另一个表,并实现模糊查询)
const sql = `select cei.intentionID,cei.engineerName,cei.nickname,cei.headImgUrl,
ifnull(cmw.headImgUrl,'') inviteImgUrl,ifnull(cmw.nickname,'') inviteNickName
from cm_engineer_intentions cei
left join cm_member_wechats cmw on cmw.referralCode=cei.inviteCode
where (:isGrant=-1 or isGrant=:isGrant)
and (:intentionStatus=-1 or intentionStatus=:intentionStatus)
and (:searchKey='' or concat(engineerMobile,engineerName) like concat('%',:searchKey,'%'))
order by intentionStatus asc,createTime desc`;
(业务需求:当某个字段有传进来时就更新,没有传进来时忽略,这样可以根据你的需求来选择是否插入某个字段)
const contactRemarkSql = isUpdateRemark ? ',contactRemark=:contactRemark' : '';
const sql = `update cm_engineer_intentions
set intentionStatus=:intentionStatus ${contactRemarkSql}
where intentionID=:intentionID`;
下面的SQL语句可以删除多条符合条件的数据
(业务需求: 进行删除操作时,创建数据的人若是操作数据的人,则删除,否则更新状态)
const deleteSql = delete from cm_fast_order_goods where orderGoodsID in (${deleteData.deleteIDs}) and createUser=:userName;
const updateSql = update cm_fast_order_goods set status=0 where orderGoodsID in (${deleteData.deleteIDs}) and createUser!=:userName;
(业务需求:新增一条新的数据)
const sqlOrderEngineer = `insert into cm_order_engineers
(orderEngineerID,orderGoodsID,orderID,engineerID,engineerName,createUser,createTime)
values
(:orderEngineerID,:orderGoodsID,:orderID,:engineerID,:engineerName,:createUser,:createTime)
(业务需求:每新增一条数据,某一字段在原有的数据的最大值基础上+1)
const sql = `insert into cm_engineers
(engineerCode,loginName,password,engineerName,sex,birthDate,status,createUser,createTime)
select
ifnull(max(engineerCode),0)+1,:loginName,:password,:engineerName,:sex,:birthDate,
:status,:createUser,now()
from cm_engineers`;
(业务需求:从其他表中新增数据到当前表)
insert into cm_fast_order_goods (orderGoodsID,orderID,goodsID,goodsCode,goodsPicUrl,createUser,createTime)
select :orderGoodsID,:orderID,:goodsID,goodsCode,iconUrl,:createUser,now()
from cm_service_goods
where goodsID=:goodsID and status=1
以上是“mysql中入门语句的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!