mysql在列之间进行比较时获取空值

时间:2018-04-03 09:57:04

标签: mysql

我认为这很简单,如何在单一条件下实现这一目标。

我有3列的表

 var intersection = function(){
    return Array.from(arguments).reduce(function(previous, current){
    return previous.filter(function(element){
      return current.indexOf(element) > -1;
   });
  });
 };

 var x = intersection([1,2,3],[2,3,4]);  // or pass n number of array as an argument
 console.log(x);

并尝试以下查询

mysql> select ID,NEW_TIME,OLD_TIME from Table;
+--------+-------------------+-------------------+
|   ID   | NEW_TIME          | OLD_TIME          |
+--------+-------------------+-------------------+
| 581318 |     1522726409000 |              NULL |
+--------+-------------------+-------------------+

在比较时,它显示了empty.how来获取这些空行。

3 个答案:

答案 0 :(得分:4)

OR IS NULL查询使用OR OLD_TIME IS NULL条件,请检查为:SELECT * FROM table WHERE NEW_TIME > OLD_TIME OR OLD_TIME IS NULL;

<?php

  if (isset($_POST['submit'])) {
    require 'connect.php';

    $username       = ($_POST['username']);
    $email          = ($_POST['email']);
    $password       = ($_POST['password']);
    $passwordconf   = ($_POST['passwordconf']);

    $errorfields    = "<p class='errormsg'>Please fill out all the fields!</p>";

    if (empty($username) || empty($email) || empty($password) || 
    empty($passwordconf))
    {
      echo "$errorfields";
    }

    $check = mysqli_query($con, "SELECT username FROM users WHERE 
    username='$username' ");

    if (mysqli_num_rows($check) >= 1) {
        echo "username already exists"."</br>". "</br>";
    }

    $erroremail     = "<p class='errormsg'>Email is not in name@domain format! </p>";
    $regex          = "/^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+.[a-z]{2,}$/i";

    if(!preg_match($regex, $email))
    {
      echo "$erroremail";
    }

    $errorpassword  = "<p class='errormsg'>You passwords do not match!</p>";

    if ($password != $passwordconf)
    {
      echo "$errorpassword";
    }

    $check = mysqli_query($con, "SELECT email FROM users WHERE email='$email' ");

    if (mysqli_num_rows($check) >= 1) {
      echo "email already exists";
    }

   } else {

    $con = mysqli_connect('localhost' , 'root', '');

    if(!$con) {
      echo "not connected";
    }

    if (!mysqli_select_db($con, "new accounts")) {
      echo "database not selected";
    }  

    $username= (isset($_POST['username']));
    $email= (isset($_POST['email']));
    $password= (isset($_POST['password']));

    mysqli_query($con, "INSERT INTO users (username, email, password) VALUE ('$username', '$email', '$password')") or die ( "cannot insert in databse");
  }

?>

答案 1 :(得分:1)

SELECT * FROM table WHERE NEW_TIME > IFNULL(OLD_TIME,0)

答案 2 :(得分:1)

您可以使用MySQL IFNULL function

SELECT * FROM table WHERE NEW_TIME > IFNULL(OLD_TIME,0);