This is a translated page. The original can be found here: http://iwebdevel.com/2010/02/03/sqlite-mysql-php-ternary-operator-if-statement-in-mysql-and-sqlite/
UPDATES VIA RSS | Email Aktualizacje pocztą RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / MySQL / PHP / SQLite / SQLite, MySQL, PHP: Ternary … Strona główna / Coding / MySQL / PHP / SQLite / SQLite, MySQL, PHP: Pieśń ...

SQLite, MySQL, PHP: Ternary operator (IF() statement) in MySQL and SQLite SQLite, MySQL, PHP: Pieśń operatora (JEŻELI () oświadczenie) w MySQL i SQLite

Posted on 03. Zamieszczone w dniu 03. Feb, 2010 by Dragos in Coding , MySQL , PHP , SQLite Luty, 2010 Dragos w Coding, MySQL, 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). Podczas pracy na zastępstwo narzędzie sprawdzania jednego z moich projektów, zmagałem na temat wykonania warunkowej zapytanie na mój bazy danych SQLite do aktualizacji kolumnie tylko wtedy, gdy jego wartość jest wyższa niż 0 (bezcelowym byłoby w moim przypadku do wynajęcia skrypt aktualizacji kolumnę wartości ujemne).

In Mysql one would do like this (we use the ternary operator IF(to_check_expression>0,expression1,expression2) ): W Mysql można by zrobić tak (używamy potrójnych operatora IF (to_check_expression> 0, wyrażenie1, wyrażenie2)):

update table_name set column_name=IF((column_name-1)>0,(column_name-1),0)

However, in SQLite this method will not work. Jednak w SQLite ta metoda nie zadziała. Instead I had to use the case when (condition) then expression1 else expression2 end method. Zamiast tego musiałem użyć w przypadku, gdy (warunek), to metoda wyrażenie1 else wyrażenie2 końca.

The above query in MySQL can be rewritten like this in SQLite: Powyższe zapytania w MySQL można zapisać tak w SQLite:

update table_name set column_name=case when (column_name-1)>0 then (column_name-1) else 0 end

That's it. That's it. I hope it helps someone! I hope it helps someone!

Translate this post Translate this post


Related posts: Podobne posty:

  1. Wordpress: Easily Reset Your Account Password Using MySQL and PHP Wordpress: łatwo zresetować Twoje konto Hasło MySQL i PHP
  2. PHP Error: Call to a member function fetch_assoc() on a non-object in PHP Error: Call to a member function fetch_assoc () w dniu wolnym od obiektu

    blog comments powered by Disqus blog komentarze powered by Disqus