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 التحديثات عن طريق آر إس إس | البريد الالكتروني Get updates via feedburner Get updates via twitter
Home / Coding / MySQL / PHP / SQLite / SQLite, MySQL, PHP: Ternary … الوطن / الترميز / ماي / [فب] / SQLite / SQLite ، الخلية ، [فب] : ترناري...

SQLite, MySQL, PHP: Ternary operator (IF() statement) in MySQL and SQLite SQLite ، الخلية ، [فب] : المشغل ترناري (اذا كان ((البيان) في الخلية وSQLite

Posted on 03. نشرت بتاريخ 03. Feb, 2010 by Dragos in Coding , MySQL , PHP , SQLite فبراير ، عام 2010 من خلال دراكوش في الترميز ، الخلية ، [فب] ، 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) ): في ماي لأحد أن يفعل مثل هذا (نستخدم ترناري التشغيل المتكامل (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: يمكن الاستعلام أعلاه في الخلية يمكن إعادة كتابة مثل هذا في 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! وآمل أن يساعد شخص!

Translate this post ترجمة هذه الوظيفة


Related posts: الوظائف ذات الصلة :

  1. Wordpress: Easily Reset Your Account Password Using MySQL and PHP وورد : بسهولة إعادة تعيين كلمة المرور الخاصة بحسابك باستخدام ماي و [فب
  2. PHP Error: Call to a member function fetch_assoc() on a non-object in [فب] خطأ : دعوة إلى وظيفة fetch_assoc عضو () على غير كائن في

    blog comments powered by Disqus بلوق التعليقات مدعوم من ديسقوس]