SQLite, MySQL, PHP: Ternary operator (IF() statement) in MySQL and SQLite SQLite는, MySQL은 PHP가 : 삼항 연산자 (MySQL과 SQLite는 () 문은)의 경우
Posted on 03. 03 게시됨. Feb, 2010 by Dragos in Coding , MySQL , PHP , SQLite 2 월, 2010 코딩, 마이 SQL, PHP는, SQLite는에서 드라 고스에 의해
While working on a proxy checker tool for one of my projects, I was struggling on how to execute a conditional query on my SQLite database to update a column only if its value is greater than 0 (it would be pointless in my case to let the script update the column with negative values). 그러나 프록시를 검사기 도구에 대한 내 사업을 위해 일하고, 난 내 SQLite는 데이터베이스를 열 경우에만이 값이 0보다 크면 (내 경우는하자에 의미가있을 것이라고 업데이 트 조건부 쿼리를 실행하는 방법에 지쳐 가고 있었는데 스크립트를) 부정적인 가치와 열을 업데이 트합니다.
In Mysql one would do like this (we use the ternary operator IF(to_check_expression>0,expression1,expression2) ): mysql을 하나에서이 (우리는 (to_check_expression "0, expression1, expression2))면 삼항 연산자를 사용하여 같이 할 것이다 :
update table_name set column_name=IF((column_name-1)>0,(column_name-1),0)
However, in SQLite this method will not work. 그러나, SQLite는이 메서드에서 작동하지 않습니다. Instead I had to use the case when (condition) then expression1 else expression2 end method. 대신 케이스를 사용해야 할 때 (조건) 다음 expression1 다른 expression2 엔드 방식입니다.
The above query in MySQL can be rewritten like this in SQLite: MySQL에서 위의 쿼리를 이런식으로 SQLite는에서 작성할 수있습니다 :
update table_name set column_name=case when (column_name-1)>0 then (column_name-1) else 0 end
That's it. 그게 다야. I hope it helps someone! 난 누군가 도움이 되길 바래요!
Related posts: 관련 게시물 :












































