MySql IN踩過的坑

2021-09-28 07:00:05 字數 2673 閱讀 6964

private dynamicparameters getparameters()

else

if (!string.isnullorempty(request.productname))

%", request.productname));

}else

if (request.fk_startcitys != null && request.fk_startcitys.any())

else

if (request.fk_areas != null && request.fk_areas.any())

else

if (request.fk_destinationplays != null && request.fk_destinationplays.any())

else

if (request.ranks != null && request.ranks.any())

else

datetime startdate;

if (!string.isnullorempty(request.startdateb) && datetime.tryparse(request.startdateb, out startdate))

else

datetime enddate;

if (!string.isnullorempty(request.startdatee) && datetime.tryparse(request.startdatee, out enddate))

else

return parameters;

}private string getwhereext()

) ", string.join(",", request.fk_destinationplays));

}return whereext;

}

select count(1) from

(select p.id

from product p

left join productext pext on pext.fk_product=p.id

left join rank r on r.id = pext.fk_rank

left join productsalescity sc on sc.fk_product=p.id and sc.isvalid='t'

inner join tour t on t.fk_product=p.id and t.isvalid='t' and t.isshowh5='t' and t.canbooking='t'

and t.expiredate>=now() and t.deadlinedate>= now() and t.`status`=2 and ifnull(t.islock,'f')<>'t'

left join tourminpriceinventory tmpi on tmpi.fk_tour=t.id

where p.isvalid='t' and p.category in (1,2,3)

and p.id=ifnull(@id,p.id)

and p.name like ifnull(@name,p.name)

and ifnull(pext.fk_destinationplay,0) in (ifnull(@fk_destinationplays,ifnull(pext.fk_destinationplay,0)))

and ifnull(pext.fk_rank,0) in (ifnull(@rank,ifnull(pext.fk_rank,0)))

and ifnull(sc.fk_city,0) in (ifnull(@fk_startcitys,ifnull(sc.fk_city,0)))

and ifnull(p.fk_area,0) in (ifnull(@fk_areas,ifnull(p.fk_area,0)))

and t.startdate >= ifnull(@startdateb,t.startdate)

and t.startdate <= ifnull(@startdatee,t.startdate)

#group by p.id

) as a;

變數@fk_destinationplays的值為:194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,306,307,308,309,349,377

其他變數均為null;

當採用寫法:and ifnull(pext.fk_destinationplay,0) in (ifnull(@fk_destinationplays,ifnull(pext.fk_destinationplay,0)))

時,會自動將變數值新增引號,造成僅匹配到fk_destinationplay為194的資料,造成sql查詢結果不準確;正確寫法為呼叫方法getwhereext,即:

and pext.fk_destinationplay in (194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,306,307,308,309,349,377)

git踩過的坑

4.git 修改當前的project的使用者名稱的命令為 git config user.name 你的目標使用者名稱 git 修改當前的project提交郵箱的命令為 git config user.email 你的目標郵箱名 如果你要修改當前全域性的使用者名稱和郵箱時,需要在上面的兩條命令中新增...

springboot踩過的坑

設定上下文路徑context path不生效 springboot 2.0之前的語法 server.context path xx 2.0之後的語法 server.servlet.context path xx 在配置yml時,報錯如下 caused by org.yaml.snakeyaml.sc...

SQL UNION踩過的坑

union 操作符用於合併兩個或多個 select 語句的結果集。請注意,union 內部的 select 語句必須擁有相同數量的列。列也必須擁有相似的資料型別。同時,每條 select 語句中的列的順序必須相同。select column name s from table name1 union...