如何清除数据以获取是(如果存在)和否(如果不存在)?

时间:2019-02-27 17:04:09

标签: mysql

我正在处理一个查询,以在满足以下条件的情况下清理以下数据。

通过检查每个条目,如果customer_ID,代理商和订单日期相同,并且其中一个条目的签名=“是”,则返回“是”,否则返回“否”。导出数据后,是否可以通过sql查询清除它而无需手动清除它?

数据示例:

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

  <script src="js/howler.core.js"></script>
  <link rel="stylesheet" href="css/styles.css">

</head>

<body>

  <script>
    (function start() {

      masterStart();

      function masterStart() {
        setTimeout(function() {
          playThunder();
          // masterStart(); // this will loop the code to play sounds continuously. the error happens with or without this
        }, 6000);
      }

      var potentialThunderSounds = [
        getSoundB('audio/58.wav'),
        getSoundB('audio/59.wav')
      ];

      function getSoundB(soundFileName) {
        return new Howl({
          src: [soundFileName],
          autoplay: false,
          loop: false,
          volume: 1,
          fade: 0
        });
      }

      // the error happens in here, I think
      function playThunder() {
        var soundSequence = [];
        for (var x = 0; x < 2; x++) {
          var soundIndex = Math.round(Math.random() * (potentialThunderSounds.length - 1));
          soundSequence.push(potentialThunderSounds[soundIndex]);
        }
        playSoundIfThereIsOne();

        function playSoundIfThereIsOne() {
          var currentSound = soundSequence[0];
          currentSound.play();
          soundSequence.shift();
          currentSound.once('end', playSoundIfThereIsOne);
        }
      }
    }());
  </script>

  <script src="js/howler.core.js"></script>
  <script src="js/siriwave.js"></script>
  <script src="js/player.js"></script>

</body>

</html>

我想要的清理数据:

  Customber_ID|Agent|Order Date|Signature
  1      | Angie | 2019-02-27 | No
  1      | Angie | 2019-02-27 | No
  1      | Angie | 2019-02-27 | Yes
  1      | Angie | 2019-02-27 | No
  2      | Roy   | 2019-02-27 | No
  2      | Roy   | 2019-02-27 | No

1 个答案:

答案 0 :(得分:1)

带有一些条件的求和函数怎么样?:

SELECT ...
    CASE WHEN SUM(CASE WHEN Signature = 'YES' THEN 1 ELSE 0 END) > 0 
        THEN 'Yes' ELSE 'No' END AS Signature
...
GROUP BY Customber_ID