Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL:条件测试_Mysql - Fatal编程技术网

Mysql SQL:条件测试

Mysql SQL:条件测试,mysql,Mysql,我想在两个计数器上测试2条件。示例下面: id_client | zipcode | timestamp | UC | MISS --------------------------------------------------|--------|------ amar | 11111 | 2016-09-28 20:05:03.001 | 15 | 0 akbar | 11111 | 2016-0

我想在两个计数器上测试2条件。示例下面:

 id_client | zipcode     | timestamp               | UC     | MISS
--------------------------------------------------|--------|------
amar      | 11111       | 2016-09-28 20:05:03.001 | 15     | 0
akbar     | 11111       | 2016-09-28 20:05:03.001 | 50     | 1  
antony    | 11111       | 2016-09-28 20:07:03.001 | 110    | 0
amar      | 11111       | 2016-09-28 20:08:03.001 | 5      | 1

select
  date (CollectionTime) as dates,
  id_client
  case when UC <=15 THEN 'TB'
    UC < 15 THEN 'TB'
    UC > 15  AND UC <=40 THEN 'B'
    UC >40  AND  UC <=80 THEN 'M'
    UC > 80 THEN 'TM'
    ELSE 'NULL' END AS tranche_UC
  case when MISS = O THEN 'BONNE'
  MISS =1 THEN 'Mauvaise'
  ELSE 'NULL' END AS note
from cm_stat 
group by id_client
order by dates;

您的查询表明,您希望最后一列为
bonne
mauvais
,而不是1或0,如示例所示。我和博恩和莫维斯一起去

首先,您有一些语法错误:

select
  date (CollectionTime) as dates,
  id_client, -- missing comma
  case
    when UC <=15 THEN 'TB'
    when UC < 15 THEN 'TB' -- needed WHEN (use before every condition)
    when UC > 15  AND UC <=40 THEN 'B' -- needed WHEN
    when UC >40  AND  UC <=80 THEN 'M' -- needed WHEN
    when UC > 80 THEN 'TM' -- needed WHEN
    ELSE 'NULL' END AS tranche_UC
  case
    when MISS = O THEN 'BONNE'
    when MISS =1 THEN 'Mauvaise' -- needed WHEN
    ELSE 'NULL' END AS note
from cm_stat 
group by id_client
order by dates;
  • id\u客户端后缺少逗号
  • 对于
    案例中的每种情况
    都需要
    WHEN
  • 以下是没有语法错误的查询:

    select
      date (CollectionTime) as dates,
      id_client, -- missing comma
      case
        when UC <=15 THEN 'TB'
        when UC < 15 THEN 'TB' -- needed WHEN (use before every condition)
        when UC > 15  AND UC <=40 THEN 'B' -- needed WHEN
        when UC >40  AND  UC <=80 THEN 'M' -- needed WHEN
        when UC > 80 THEN 'TM' -- needed WHEN
        ELSE 'NULL' END AS tranche_UC
      case
        when MISS = O THEN 'BONNE'
        when MISS =1 THEN 'Mauvaise' -- needed WHEN
        ELSE 'NULL' END AS note
    from cm_stat 
    group by id_client
    order by dates;
    

    您的查询表明,您希望最后一列为
    bonne
    mauvais
    ,而不是1或0,如示例所示。我和博恩和莫维斯一起去

    首先,您有一些语法错误:

    select
      date (CollectionTime) as dates,
      id_client, -- missing comma
      case
        when UC <=15 THEN 'TB'
        when UC < 15 THEN 'TB' -- needed WHEN (use before every condition)
        when UC > 15  AND UC <=40 THEN 'B' -- needed WHEN
        when UC >40  AND  UC <=80 THEN 'M' -- needed WHEN
        when UC > 80 THEN 'TM' -- needed WHEN
        ELSE 'NULL' END AS tranche_UC
      case
        when MISS = O THEN 'BONNE'
        when MISS =1 THEN 'Mauvaise' -- needed WHEN
        ELSE 'NULL' END AS note
    from cm_stat 
    group by id_client
    order by dates;
    
  • id\u客户端后缺少逗号
  • 对于
    案例中的每种情况
    都需要
    WHEN
  • 以下是没有语法错误的查询:

    select
      date (CollectionTime) as dates,
      id_client, -- missing comma
      case
        when UC <=15 THEN 'TB'
        when UC < 15 THEN 'TB' -- needed WHEN (use before every condition)
        when UC > 15  AND UC <=40 THEN 'B' -- needed WHEN
        when UC >40  AND  UC <=80 THEN 'M' -- needed WHEN
        when UC > 80 THEN 'TM' -- needed WHEN
        ELSE 'NULL' END AS tranche_UC
      case
        when MISS = O THEN 'BONNE'
        when MISS =1 THEN 'Mauvaise' -- needed WHEN
        ELSE 'NULL' END AS note
    from cm_stat 
    group by id_client
    order by dates;