Mysql案例语法

时间:2015-06-01 07:15:12

标签: php mysql

SELECT *
FROM case_study
ORDER BY CASE WHEN expiry_date_case > CURDATE() THEN 1 END
WHEN expiry_date_case IS NULL THEN 2 Desc END
WHEN expire_date_case < CURDATE() THEN 3 Desc END;

当我尝试运行此查询时,我收到错误

  

#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以获得正确的语法   在'WHEN expiry_date_case IS NULL那么2描述结束时   expire_date_case&lt;第4行的CURDATE()'

我在哪里做错了?

2 个答案:

答案 0 :(得分:3)

尝试

<!DOCTYPE html>
<html style="height:100%;margin:0;padding:0;width:100%">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
  <body style="background:#212121;height:100%;margin:0;padding:0">

<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player" style="margin:0;padding:0"></div>

<script>

    var Query = function () {

    var query_string = {};
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");

    if (typeof query_string[pair[0]] === "undefined") {
      query_string[pair[0]] = pair[1];

    } else if (typeof query_string[pair[0]] === "string") {
      var arr = [ query_string[pair[0]], pair[1] ];
      query_string[pair[0]] = arr;

    } else {
      query_string[pair[0]].push(pair[1]);
    }
    } 

    return query_string;
    } ();

    var tag = document.createElement('script');

    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    var player;
    function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
    height:'100%',width:'100%',

    videoId: Query.videoid,
    playerVars: { 'autoplay': 0, 'controls': 0, 'showinfo':0, 'modestbranding':1},
    events: {

    'onReady': onPlayerReady,
    'onStateChange': onPlayerStateChange

    }
    });


  }

  function onPlayerReady(event) {
  cueCheck();
  timerFunction();
  videoLength();
  }

  var done = false;

  function onPlayerStateChange(event) {
    Android.playState(event.data+"");

    if (event.data == YT.PlayerState.PLAYING && !done) {
      done = true;
    }
  }

  function cueCheck()
  {
    Android.playState("cued");
  }

  function timerFunction(){
  console.log("function");
  Android.updateTimer(player.getCurrentTime()+"");
  setTimeout(timerFunction, 20);
 }

 function videoLength(){
  Android.getVideoLength(player.getDuration()+"");
 }

  function seekTo(val) {
  player.seekTo(val);
  // player.playVideo();
  }

  function pauseVideo(){
  player.pauseVideo()
  }

  function playVideo(){
  player.playVideo()
  }



    </script>

  </body>
</html>

你有太多SELECT * FROM case_study ORDER BY CASE WHEN expiry_date_case > CURDATE() THEN 1 WHEN expiry_date_case IS NULL THEN 2 WHEN expire_date_case < CURDATE() THEN 3 END Desc 和太多End

答案 1 :(得分:1)

将您的查询更新为

a1.each do |a1_hash|
  matching_hash = a2.find { |a2_hash| data_matches?(a1_hash, a2_hash) } if a2.present?
  a1_hash["ORDER_NO"] = a2_hash["ORDER_NO"] if matching_hash.present?
  a2.delete(a2_hash)
end

删除了SELECT * FROM case_study ORDER BY CASE WHEN expiry_date_case > CURDATE() THEN 1 WHEN expiry_date_case IS NULL THEN 2 WHEN expire_date_case < CURDATE() THEN 3 END Desc end