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 FRISSÍTÉSEK VIA RSS | E-mail Get updates via feedburner Get updates via twitter
Home / Coding / MySQL / PHP / SQLite / SQLite, MySQL, PHP: Ternary … Home / Coding / MySQL / PHP / SQLite / SQLite, MySQL, PHP: ternáris ...

SQLite, MySQL, PHP: Ternary operator (IF() statement) in MySQL and SQLite SQLite, MySQL, PHP: ternáris operátor (HA () utasítás) a MySQL és SQLite

Posted on 03. Posted on 03. Feb, 2010 by Dragos in Coding , MySQL , PHP , SQLite Február, 2010 by Dragos az Kódolás, MySQL, PHP, SQLite kiterjesztés

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). Míg a munka a proxy-ellenőrző eszköz az egyik projekt, én hogyan küzd meg végrehajtani feltételes lekérdezést én SQLite adatbázis frissítése egy oszlopot csak akkor, ha az érték több mint 0 (nem lenne értelme az én esetemben, hogy hagyja, hogy a script frissítés az oszlopot a negatív érték).

In Mysql one would do like this (we use the ternary operator IF(to_check_expression>0,expression1,expression2) ): Mysql-ben egy akar csinálni, mint ez (használjuk a háromoperandusú üzemeltető IF (to_check_expression> 0, kifejezés1, kifejezés2)):

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

However, in SQLite this method will not work. Ugyanakkor, SQLite ez a módszer nem fog működni. Instead I had to use the case when (condition) then expression1 else expression2 end method. Ehelyett kellett használni az esetben, ha (feltétel), akkor kifejezés1 else kifejezés2 vége módszer.

The above query in MySQL can be rewritten like this in SQLite: A fenti lekérdezés a MySQL átírható, mint ez 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! Remélem ez segít valaki!

Translate this post Translate this post


Related posts: Related posts:

  1. Wordpress: Easily Reset Your Account Password Using MySQL and PHP Wordpress: Könnyen Reset Your Account jelszót a MySQL és a 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 () on a non-object in
  3. PHP: Script to extract one's contacts from email (Gmail, Yahoo,Hotmail,AOL…) and send invites – OpenInviter to go! PHP: Script kell bontania egy kapcsolatait az e-mail (Gmail, Yahoo, Hotmail, AOL ...) és küld meghív - OpenInviter to go!

    blog comments powered by Disqus iPhone Disqus szerint