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 GÜNCELLEME VIA RSS | E-posta Get updates via feedburner Get updates via twitter
Home / Coding / MySQL / PHP / SQLite / SQLite, MySQL, PHP: Ternary … Ana Sayfa / Kodlama / MySQL / PHP / SQLite / SQLite, MySQL, PHP: Üçlü ...

SQLite, MySQL, PHP: Ternary operator (IF() statement) in MySQL and SQLite SQLite, MySQL, PHP: Üçlü operatör (MySQL ve SQLite () deyimi olarak) IF

Posted on 03. 03 olarak gönderildi. Feb, 2010 by Dragos in Coding , MySQL , PHP , SQLite Şubat, 2010 Kodlama, MySQL, PHP, SQLite içinde Dragos tarafından

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). Bir vekil ekose desenli aracında biri benim projeler için çalışan, ben nasıl SQLite veritabanında bir sütun yalnızca değerini 0 dan büyük (benim halinde izin vermek anlamsız olacağını güncellemek için şartlı bir sorgu çalıştırmak için çalışıyordu script) negatif değerler ile sütun güncelleyin.

In Mysql one would do like this (we use the ternary operator IF(to_check_expression>0,expression1,expression2) ): Mysql bir (bu biz (to_check_expression> 0, expression1, expression2)) IF üçlü işlecini gibi yapardı:

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

However, in SQLite this method will not work. Ancak, SQLite bu yöntem çalışmayacaktır. Instead I had to use the case when (condition) then expression1 else expression2 end method. Onun yerine durumda kullanmak zorundayım zaman (durumu) daha sonra expression1 başka expression2 sonuna yöntemi.

The above query in MySQL can be rewritten like this in SQLite: MySQL Yukarıdaki sorgu böyle SQLite içinde yeniden olabilir:

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! Bunu kimse yardımcı umut!

Translate this post Translate bu yazı


Related posts: Ilgili posta:

  1. Wordpress: Easily Reset Your Account Password Using MySQL and PHP Wordpress: kolayca hesap şifrenizi MySQL ve PHP'nin sıfırla
  2. PHP Error: Call to a member function fetch_assoc() on a non-object in PHP Hata: Üye için fetch_assoc olmayan () on-nesne fonksiyonu Arama

    blog comments powered by Disqus Blog Yorumlar Disqus tarafından desteklenmektedir