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#n#leftp. 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=:tenentionStatus ${contactRemarkSw; intentionID`;
(業務需求: 進行刪除操作時,創建資料的人若是操作資料的人,則刪除,否則更新狀態)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##:NameGoodsID in (${deleteData.deleteIDs}) and createUser##:NameGoodData;
##Insert的用法
const sqlOrderEngineer = ` insert into cm_order_engineers(orderEngineerID,orderGoodsID,orderID,engineerID,engineerName,createUser,createTime)
values(:orderEngineerID,:orderGoodsID,:orderID,:engineerID,:##(:orderEngineerID,:orderGoodsID,:orderID,:engineerID,:0engineerName:createUser)
(業務需求:每新增一條數據,某一欄位在原有的資料的最大值基礎上+1)
const sql = `insert into cm_engineers(engineerCode,loginName,password,engineerName,sex,birthDate,status,createUser,createTime)
select :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語句加鎖的方法
以上是mysql語句入門詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!