. .

    @Mail.ru -

6.3: MySQL

» PHP » MySQL » MySQL

MySQL 1 (, TRUE), 0 (, FALSE) NULL ( ). . , , .

MySQL , :

  • , NULL, NULL, <=>;
  • , ;
  • , ;
  • , ;
  • TIMESTAMP DATETIME, , timestamp , ;
  • ().

, ( ISO-8859-1 Latin1, ).

:

mysql> SELECT 1 > "6x";
-> 0
mysql> SELECT 7 > "6x";
-> 1
mysql> SELECT 0 > "x6";
->'0
mysql> SELECT 0 = "x6";
-> 1

(=):

mysql> select 1 = 0;
-> 0
mysql> select "0" = 0;
-> 1
mysql> select 0.0' = 0;
-> 1
mysql> select '0.01' ='0;
-> 0
mysql> select ".01" = 0.01;
-> 1

He (<> ! =):

mysql> select ".01" <> "0.01:
-> 1
mysql> select .01 <> "0.01"
-> 0
mysql> select "zapp" <> "zappp"
-> 1

, (<=):

mysql> select 0.1 <= 2;
-> 1

, (<):

mysql> select 2 < 2;
-> 0

, (>=):

mysql> select 2 >= 2;
-> 1

, (>):

mysql> select 2 > 2;
-> 0

Null (<=>):

mysql> select 1 <=> 1, NULL <=> NULL, 1 <=> NULL;
->1 1 0

IS NULL IS NOT NULL.
, NULL:

mysql> select 1 IS NULL, 0 IS NULL, NULL IS NULL;
->0 0 1
mysql> select 1 IS NOT NULL, 0 IS NOT NULL, NULL IS NOT NULL;
->1 1 0

expr BETWEEN min AND max.

expr min, max, BETWEEN 1, 0. (min <= expr AND expr <= max), . () , , :

  • r TIMESTAMP, DATE DATETIME, MIN() () , ;
  • r , , ;
  • r , , ;
  • r , ;
  • , .
mysql> select 1 BETWEEN 2 AND 3;
    -> 0
mysql> select "b" BETWEEN "a" AND "c";
    -> 1
mysql> select 2 BETWEEN 2 AND "3";
    -> 1
mysql> select 2 BETWEEN 2 AND "x-3";
    -> 0

expr IN (value,...).

1, expr IN, 0. - , r . . , IN , IN . r - , :

mysql> select 2 IN (0,3,5,'wefwf');
    -> 0
mysql> select "wefwf IN (0,3,5,'wefwf');
    -> 1

expr NOT IN (value,...)

NOT (expr IN (value,...)).

ISNULL(expr).

expr NULL, ISNULL() 1, 0:

mysql> select ISNULL(1+1);
    -> 0
mysql> select ISNULL(1/0);
    -> 1

, NULL, =, false!

COALESCE(list).

-NULL :

mysql> select COALESCE(NULL,1);
    -> 1
mysql> select COALESCE(NULL,NULL,NULL);
    -> NULL

INTERVAL(N,N1,N2,N3,...)

0, N < N1, 1, N < N2 . . , : N1 < N2 < N3 < ... < Nn , . , ( ):

mysql> select INTERVAL(23, 1, 15, 17, 30, 44, 200);
    -> 3
mysql> select INTERVAL(10, 1, 10, 100, 1000);
    -> 2
mysql> select INTERVAL(22, 23, 30, 44, 200);
    -> 0

(=, <>..., LIKE), .

mysql> select "" = ";
    -> 1