问:
Bug Occurs In My Exported Excel File
I have an HTML table with some text and some radio buttons. When you click the 'Export to Excel' button it exports the values of the HTML table along with the values of any radio buttons selected in the table as well.

However, if any of the radio buttons have been selected and I click the 'Export to Excel' button it merges two of the cells together to contain the text of the table, it does not do this if none of the radio buttons have been selected.

As you can see from the image all the table cells that didn't contain any radio buttons have two cells merged together such as the cells A4 & A5. However if you look at Row 3 where none of the radio buttons were selected none of the cells got merged together.

I have tried this on several computers and on several different versions of Excel and OpenOffice Calc without any success so I don't think it's Excel that is the problem. I am not sure what is causing the problem and some enlightenment on the issue would be very helpful.

Here's the link to the fiddle and the snippet is below:

 var overall= $('#overall');

    $(document).ready(function() {
      $(':radio').change(function(e) {
        var row = $(this).closest('.item');
        var checkedItems = row.find(":checked:not(:radio[name='attendance'])")
      if(e.target.name != "attendance"){

        if (checkedItems.length == 5) {
          row.find("td.overall").html(getOverall(checkedItems));
        }
      }else{
        row.find("td.attendance").html("x "+parseFloat($(this).val()/10).toFixed(1));
      }
    })

    function getOverall(_checkedItems) {
    var total = 0;
    _checkedItems.each(function() {
    total += parseFloat($(this).val());
    });
    return total;
    }

    });

var tableToExcel = (function() {

  var uri = 'data:application/vnd.ms-excel;base64,',
    template = '<\/head>
{table}<\/table><\/body><\/html>',
    base64 = function(s) {
      return window.btoa(unescape(encodeURIComponent(s)))
    },
    format = function(s, c) {
      return s.replace(/{(\w+)}/g, function(m, p) {
        return c[p];
      })
    }
  return function(table, name) {
    if (!table.nodeType) {
    table = document.getElementById(table)}
    var cloned = $('#copyTable').clone().appendTo('.hidden_table')
    cloned.find('input[type="radio"]:not(:checked) + span').remove();

    var ctx = {
      worksheet: name || 'Worksheet',
      table: cloned.html()
    }
    cloned.remove();
    window.location.href = uri + base64(format(template, ctx));
  }
})();```
<pre class="snippet-code-css lang-css prettyprint-override"><code>table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 115%;
}

td,
th {
  border: 1px solid #dddddd;
  text-align: center;
}

tr:nth-child(even) {
  background-color: #dddddd;
}

.hidden_table{
/*display:none*/
}</code>```

  Team
  Player
  Number
  Position
  Skating
  Shooting
  Passing
  Puck Control
  Game Understanding
  Attendance
  Overall
  Attendance
Factor

    <form action="">
      <input type="radio" name="skating" value="1">1
      <input type="radio" name="skating" value="2">2
      <input type="radio" name="skating" value="3">3
      <input type="radio" name="skating" value="4">4
      <input type="radio" name="skating" value="5">5

      <input type="radio" name="skating" value="6">6
      <input type="radio" name="skating" value="7">7
      <input type="radio" name="skating" value="8">8
      <input type="radio" name="skating" value="9">9
      <input type="radio" name="skating" value="10">10
    </form>

    <form action="">
      <input type="radio" name="shooting" value="1">1
      <input type="radio" name="shooting" value="2">2
      <input type="radio" name="shooting" value="3">3
      <input type="radio" name="shooting" value="4">4
      <input type="radio" name="shooting" value="5">5

      <input type="radio" name="shooting" value="6">6
      <input type="radio" name="shooting" value="7">7
      <input type="radio" name="shooting" value="8">8
      <input type="radio" name="shooting" value="9">9
      <input type="radio" name="shooting" value="10">10
    </form>

    <form action="">
      <input type="radio" name="passing" value="1">1
      <input type="radio" name="passing" value="2">2
      <input type="radio" name="passing" value="3">3
      <input type="radio" name="passing" value="4">4
      <input type="radio" name="passing" value="5">5

      <input type="radio" name="passing" value="6">6
      <input type="radio" name="passing" value="7">7
      <input type="radio" name="passing" value="8">8
      <input type="radio" name="passing" value="9">9
      <input type="radio" name="passing" value="10">10
    </form>

    <form action="">
      <input type="radio" name="puck_control" value="1">1
      <input type="radio" name="puck_control" value="2">2
      <input type="radio" name="puck_control" value="3">3
      <input type="radio" name="puck_control" value="4">4
      <input type="radio" name="puck_control" value="5">5

      <input type="radio" name="puck_control" value="6">6
      <input type="radio" name="puck_control" value="7">7
      <input type="radio" name="puck_control" value="8">8
      <input type="radio" name="puck_control" value="9">9
      <input type="radio" name="puck_control" value="10">10
    </form>

    <form action="">
      <input type="radio" name="team_play" value="1">1
      <input type="radio" name="team_play" value="2">2
      <input type="radio" name="team_play" value="3">3
      <input type="radio" name="team_play" value="4">4
      <input type="radio" name="team_play" value="5">5

      <input type="radio" name="team_play" value="6">6
      <input type="radio" name="team_play" value="7">7
      <input type="radio" name="team_play" value="8">8
      <input type="radio" name="team_play" value="9">9
      <input type="radio" name="team_play" value="10">10
    </form>

    <form action="">
      <input type="radio" name="attendance" value="1">1
      <input type="radio" name="attendance" value="2">2
      <input type="radio" name="attendance" value="3">3
      <input type="radio" name="attendance" value="4">4
      <input type="radio" name="attendance" value="5">5

      <input type="radio" name="attendance" value="6">6
      <input type="radio" name="attendance" value="7">7
      <input type="radio" name="attendance" value="8">8
      <input type="radio" name="attendance" value="9">9
      <input type="radio" name="attendance" value="10">10
    </form>

    <form action="">
      <input type="radio" name="skating" value="1">1
      <input type="radio" name="skating" value="2">2
      <input type="radio" name="skating" value="3">3
      <input type="radio" name="skating" value="4">4
      <input type="radio" name="skating" value="5">5

      <input type="radio" name="skating" value="6">6
      <input type="radio" name="skating" value="7">7
      <input type="radio" name="skating" value="8">8
      <input type="radio" name="skating" value="9">9
      <input type="radio" name="skating" value="10">10
    </form>

    <form action="">
      <input type="radio" name="shooting" value="1">1
      <input type="radio" name="shooting" value="2">2
      <input type="radio" name="shooting" value="3">3
      <input type="radio" name="shooting" value="4">4
      <input type="radio" name="shooting" value="5">5

      <input type="radio" name="shooting" value="6">6
      <input type="radio" name="shooting" value="7">7
      <input type="radio" name="shooting" value="8">8
      <input type="radio" name="shooting" value="9">9
      <input type="radio" name="shooting" value="10">10
    </form>

    <form action="">
      <input type="radio" name="passing" value="1">1
      <input type="radio" name="passing" value="2">2
      <input type="radio" name="passing" value="3">3
      <input type="radio" name="passing" value="4">4
      <input type="radio" name="passing" value="5">5

      <input type="radio" name="passing" value="6">6
      <input type="radio" name="passing" value="7">7
      <input type="radio" name="passing" value="8">8
      <input type="radio" name="passing" value="9">9
      <input type="radio" name="passing" value="10">10
    </form>

    <form action="">
      <input type="radio" name="puck_control" value="1">1
      <input type="radio" name="puck_control" value="2">2
      <input type="radio" name="puck_control" value="3">3
      <input type="radio" name="puck_control" value="4">4
      <input type="radio" name="puck_control" value="5">5

      <input type="radio" name="puck_control" value="6">6
      <input type="radio" name="puck_control" value="7">7
      <input type="radio" name="puck_control" value="8">8
      <input type="radio" name="puck_control" value="9">9
      <input type="radio" name="puck_control" value="10">10
    </form>

    <form action="">
      <input type="radio" name="team_play" value="1">1
      <input type="radio" name="team_play" value="2">2
      <input type="radio" name="team_play" value="3">3
      <input type="radio" name="team_play" value="4">4
      <input type="radio" name="team_play" value="5">5

      <input type="radio" name="team_play" value="6">6
      <input type="radio" name="team_play" value="7">7
      <input type="radio" name="team_play" value="8">8
      <input type="radio" name="team_play" value="9">9
      <input type="radio" name="team_play" value="10">10
    </form>

    <form action="">
      <input type="radio" name="attendance" value="1">1
      <input type="radio" name="attendance" value="2">2
      <input type="radio" name="attendance" value="3">3
      <input type="radio" name="attendance" value="4">4
      <input type="radio" name="attendance" value="5">5

      <input type="radio" name="attendance" value="6">6
      <input type="radio" name="attendance" value="7">7
      <input type="radio" name="attendance" value="8">8
      <input type="radio" name="attendance" value="9">9
      <input type="radio" name="attendance" value="10">10
    </form>

  <input type="button" onclick="tableToExcel('copyTable', 'Player_scores')" value="Export to Excel">

```

答:
The problem is caused by
 tags in the table cells. Remove them when preparing the export as I do below. Another option is excluding
 from the HTML.

Also you can omit <form> tags. And the better practice is to use  instead of  like this: <input type="radio" name="skating" value="1">1.

Good luck!

 var overall= $('#overall');

    $(document).ready(function() {
      $(':radio').change(function(e) {
        var row = $(this).closest('.item');
        var checkedItems = row.find(":checked:not(:radio[name='attendance'])")
      if(e.target.name != "attendance"){

        if (checkedItems.length == 5) {
          row.find("td.overall").html(getOverall(checkedItems));
        }
      }else{
        row.find("td.attendance").html("x "+parseFloat($(this).val()/10).toFixed(1));
      }
    })

    function getOverall(_checkedItems) {
    var total = 0;
    _checkedItems.each(function() {
    total += parseFloat($(this).val());
    });
    return total;
    }

    });

var tableToExcel = (function() {

  var uri = 'data:application/vnd.ms-excel;base64,',
    template = '<\/head>
{table}<\/table><\/body><\/html>',
    base64 = function(s) {
      return window.btoa(unescape(encodeURIComponent(s)))
    },
    format = function(s, c) {
      return s.replace(/{(\w+)}/g, function(m, p) {
        return c[p];
      })
    }
  return function(table, name) {
    if (!table.nodeType) {
    table = document.getElementById(table)}
    var cloned = $('#copyTable').clone().appendTo('.hidden_table')
    cloned.find('input[type="radio"]:not(:checked) + span').remove()
    .end().find('br').remove();

    var ctx = {
      worksheet: name || 'Worksheet',
      table: cloned.html()
    }
    cloned.remove();
    window.location.href = uri + base64(format(template, ctx));
  }
})();```
<pre class="snippet-code-css lang-css prettyprint-override"><code>table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 115%;
}

td,
th {
  border: 1px solid #dddddd;
  text-align: center;
}

tr:nth-child(even) {
  background-color: #dddddd;
}

.hidden_table{
/*display:none*/
}</code>```

  Team
  Player
  Number
  Position
  Skating
  Shooting
  Passing
  Puck Control
  Game Understanding
  Attendance
  Overall
  Attendance Factor

    <form action="">
      <input type="radio" name="skating" value="1">1
      <input type="radio" name="skating" value="2">2
      <input type="radio" name="skating" value="3">3
      <input type="radio" name="skating" value="4">4
      <input type="radio" name="skating" value="5">5

      <input type="radio" name="skating" value="6">6
      <input type="radio" name="skating" value="7">7
      <input type="radio" name="skating" value="8">8
      <input type="radio" name="skating" value="9">9
      <input type="radio" name="skating" value="10">10
    </form>

    <form action="">
      <input type="radio" name="shooting" value="1">1
      <input type="radio" name="shooting" value="2">2
      <input type="radio" name="shooting" value="3">3
      <input type="radio" name="shooting" value="4">4
      <input type="radio" name="shooting" value="5">5

      <input type="radio" name="shooting" value="6">6
      <input type="radio" name="shooting" value="7">7
      <input type="radio" name="shooting" value="8">8
      <input type="radio" name="shooting" value="9">9
      <input type="radio" name="shooting" value="10">10
    </form>

    <form action="">
      <input type="radio" name="passing" value="1">1
      <input type="radio" name="passing" value="2">2
      <input type="radio" name="passing" value="3">3
      <input type="radio" name="passing" value="4">4
      <input type="radio" name="passing" value="5">5

      <input type="radio" name="passing" value="6">6
      <input type="radio" name="passing" value="7">7
      <input type="radio" name="passing" value="8">8
      <input type="radio" name="passing" value="9">9
      <input type="radio" name="passing" value="10">10
    </form>

    <form action="">
      <input type="radio" name="puck_control" value="1">1
      <input type="radio" name="puck_control" value="2">2
      <input type="radio" name="puck_control" value="3">3
      <input type="radio" name="puck_control" value="4">4
      <input type="radio" name="puck_control" value="5">5

      <input type="radio" name="puck_control" value="6">6
      <input type="radio" name="puck_control" value="7">7
      <input type="radio" name="puck_control" value="8">8
      <input type="radio" name="puck_control" value="9">9
      <input type="radio" name="puck_control" value="10">10
    </form>

    <form action="">
      <input type="radio" name="team_play" value="1">1
      <input type="radio" name="team_play" value="2">2
      <input type="radio" name="team_play" value="3">3
      <input type="radio" name="team_play" value="4">4
      <input type="radio" name="team_play" value="5">5

      <input type="radio" name="team_play" value="6">6
      <input type="radio" name="team_play" value="7">7
      <input type="radio" name="team_play" value="8">8
      <input type="radio" name="team_play" value="9">9
      <input type="radio" name="team_play" value="10">10
    </form>

    <form action="">
      <input type="radio" name="attendance" value="1">1
      <input type="radio" name="attendance" value="2">2
      <input type="radio" name="attendance" value="3">3
      <input type="radio" name="attendance" value="4">4
      <input type="radio" name="attendance" value="5">5

      <input type="radio" name="attendance" value="6">6
      <input type="radio" name="attendance" value="7">7
      <input type="radio" name="attendance" value="8">8
      <input type="radio" name="attendance" value="9">9
      <input type="radio" name="attendance" value="10">10
    </form>

    <form action="">
      <input type="radio" name="skating" value="1">1
      <input type="radio" name="skating" value="2">2
      <input type="radio" name="skating" value="3">3
      <input type="radio" name="skating" value="4">4
      <input type="radio" name="skating" value="5">5

      <input type="radio" name="skating" value="6">6
      <input type="radio" name="skating" value="7">7
      <input type="radio" name="skating" value="8">8
      <input type="radio" name="skating" value="9">9
      <input type="radio" name="skating" value="10">10
    </form>

    <form action="">
      <input type="radio" name="shooting" value="1">1
      <input type="radio" name="shooting" value="2">2
      <input type="radio" name="shooting" value="3">3
      <input type="radio" name="shooting" value="4">4
      <input type="radio" name="shooting" value="5">5

      <input type="radio" name="shooting" value="6">6
      <input type="radio" name="shooting" value="7">7
      <input type="radio" name="shooting" value="8">8
      <input type="radio" name="shooting" value="9">9
      <input type="radio" name="shooting" value="10">10
    </form>

    <form action="">
      <input type="radio" name="passing" value="1">1
      <input type="radio" name="passing" value="2">2
      <input type="radio" name="passing" value="3">3
      <input type="radio" name="passing" value="4">4
      <input type="radio" name="passing" value="5">5

      <input type="radio" name="passing" value="6">6
      <input type="radio" name="passing" value="7">7
      <input type="radio" name="passing" value="8">8
      <input type="radio" name="passing" value="9">9
      <input type="radio" name="passing" value="10">10
    </form>

    <form action="">
      <input type="radio" name="puck_control" value="1">1
      <input type="radio" name="puck_control" value="2">2
      <input type="radio" name="puck_control" value="3">3
      <input type="radio" name="puck_control" value="4">4
      <input type="radio" name="puck_control" value="5">5

      <input type="radio" name="puck_control" value="6">6
      <input type="radio" name="puck_control" value="7">7
      <input type="radio" name="puck_control" value="8">8
      <input type="radio" name="puck_control" value="9">9
      <input type="radio" name="puck_control" value="10">10
    </form>

    <form action="">
      <input type="radio" name="team_play" value="1">1
      <input type="radio" name="team_play" value="2">2
      <input type="radio" name="team_play" value="3">3
      <input type="radio" name="team_play" value="4">4
      <input type="radio" name="team_play" value="5">5

      <input type="radio" name="team_play" value="6">6
      <input type="radio" name="team_play" value="7">7
      <input type="radio" name="team_play" value="8">8
      <input type="radio" name="team_play" value="9">9
      <input type="radio" name="team_play" value="10">10
    </form>

    <form action="">
      <input type="radio" name="attendance" value="1">1
      <input type="radio" name="attendance" value="2">2
      <input type="radio" name="attendance" value="3">3
      <input type="radio" name="attendance" value="4">4
      <input type="radio" name="attendance" value="5">5

      <input type="radio" name="attendance" value="6">6
      <input type="radio" name="attendance" value="7">7
      <input type="radio" name="attendance" value="8">8
      <input type="radio" name="attendance" value="9">9
      <input type="radio" name="attendance" value="10">10
    </form>

  <input type="button" onclick="tableToExcel('copyTable', 'Player_scores')" value="Export to Excel">

```

Title: Bug Occurs In My Exported Excel File

Body:
I have an HTML table with some text and some radio buttons. When you click the 'Export to Excel' button it exports the values of the HTML table along with the values of any radio buttons selected in the table as well.

However, if any of the radio buttons have been selected and I click the 'Export to Excel' button it merges two of the cells together to contain the text of the table, it does not do this if none of the radio buttons have been selected.

As you can see from the image all the table cells that didn't contain any radio buttons have two cells merged together such as the cells A4 & A5. However if you look at Row 3 where none of the radio buttons were selected none of the cells got merged together.

I have tried this on several computers and on several different versions of Excel and OpenOffice Calc without any success so I don't think it's Excel that is the problem. I am not sure what is causing the problem and some enlightenment on the issue would be very helpful.

Here's the link to the fiddle and the snippet is below:

 var overall= $('#overall');

    $(document).ready(function() {
      $(':radio').change(function(e) {
        var row = $(this).closest('.item');
        var checkedItems = row.find(":checked:not(:radio[name='attendance'])")
      if(e.target.name != "attendance"){

        if (checkedItems.length == 5) {
          row.find("td.overall").html(getOverall(checkedItems));
        }
      }else{
        row.find("td.attendance").html("x "+parseFloat($(this).val()/10).toFixed(1));
      }
    })

    function getOverall(_checkedItems) {
    var total = 0;
    _checkedItems.each(function() {
    total += parseFloat($(this).val());
    });
    return total;
    }

    });

var tableToExcel = (function() {

  var uri = 'data:application/vnd.ms-excel;base64,',
    template = '<\/head>
{table}<\/table><\/body><\/html>',
    base64 = function(s) {
      return window.btoa(unescape(encodeURIComponent(s)))
    },
    format = function(s, c) {
      return s.replace(/{(\w+)}/g, function(m, p) {
        return c[p];
      })
    }
  return function(table, name) {
    if (!table.nodeType) {
    table = document.getElementById(table)}
    var cloned = $('#copyTable').clone().appendTo('.hidden_table')
    cloned.find('input[type="radio"]:not(:checked) + span').remove();

    var ctx = {
      worksheet: name || 'Worksheet',
      table: cloned.html()
    }
    cloned.remove();
    window.location.href = uri + base64(format(template, ctx));
  }
})();

table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 115%;
}

td,
th {
  border: 1px solid #dddddd;
  text-align: center;
}

tr:nth-child(even) {
  background-color: #dddddd;
}

.hidden_table{
/*display:none*/
}

  Team
  Player
  Number
  Position
  Skating
  Shooting
  Passing
  Puck Control
  Game Understanding
  Attendance
  Overall
  Attendance
Factor

    <form action="">
      <input type="radio" name="skating" value="1">1
      <input type="radio" name="skating" value="2">2
      <input type="radio" name="skating" value="3">3
      <input type="radio" name="skating" value="4">4
      <input type="radio" name="skating" value="5">5

      <input type="radio" name="skating" value="6">6
      <input type="radio" name="skating" value="7">7
      <input type="radio" name="skating" value="8">8
      <input type="radio" name="skating" value="9">9
      <input type="radio" name="skating" value="10">10
    </form>

    <form action="">
      <input type="radio" name="shooting" value="1">1
      <input type="radio" name="shooting" value="2">2
      <input type="radio" name="shooting" value="3">3
      <input type="radio" name="shooting" value="4">4
      <input type="radio" name="shooting" value="5">5

      <input type="radio" name="shooting" value="6">6
      <input type="radio" name="shooting" value="7">7
      <input type="radio" name="shooting" value="8">8
      <input type="radio" name="shooting" value="9">9
      <input type="radio" name="shooting" value="10">10
    </form>

    <form action="">
      <input type="radio" name="passing" value="1">1
      <input type="radio" name="passing" value="2">2
      <input type="radio" name="passing" value="3">3
      <input type="radio" name="passing" value="4">4
      <input type="radio" name="passing" value="5">5

      <input type="radio" name="passing" value="6">6
      <input type="radio" name="passing" value="7">7
      <input type="radio" name="passing" value="8">8
      <input type="radio" name="passing" value="9">9
      <input type="radio" name="passing" value="10">10
    </form>

    <form action="">
      <input type="radio" name="puck_control" value="1">1
      <input type="radio" name="puck_control" value="2">2
      <input type="radio" name="puck_control" value="3">3
      <input type="radio" name="puck_control" value="4">4
      <input type="radio" name="puck_control" value="5">5

      <input type="radio" name="puck_control" value="6">6
      <input type="radio" name="puck_control" value="7">7
      <input type="radio" name="puck_control" value="8">8
      <input type="radio" name="puck_control" value="9">9
      <input type="radio" name="puck_control" value="10">10
    </form>

    <form action="">
      <input type="radio" name="team_play" value="1">1
      <input type="radio" name="team_play" value="2">2
      <input type="radio" name="team_play" value="3">3
      <input type="radio" name="team_play" value="4">4
      <input type="radio" name="team_play" value="5">5

      <input type="radio" name="team_play" value="6">6
      <input type="radio" name="team_play" value="7">7
      <input type="radio" name="team_play" value="8">8
      <input type="radio" name="team_play" value="9">9
      <input type="radio" name="team_play" value="10">10
    </form>

    <form action="">
      <input type="radio" name="attendance" value="1">1
      <input type="radio" name="attendance" value="2">2
      <input type="radio" name="attendance" value="3">3
      <input type="radio" name="attendance" value="4">4
      <input type="radio" name="attendance" value="5">5

      <input type="radio" name="attendance" value="6">6
      <input type="radio" name="attendance" value="7">7
      <input type="radio" name="attendance" value="8">8
      <input type="radio" name="attendance" value="9">9
      <input type="radio" name="attendance" value="10">10
    </form>

    <form action="">
      <input type="radio" name="skating" value="1">1
      <input type="radio" name="skating" value="2">2
      <input type="radio" name="skating" value="3">3
      <input type="radio" name="skating" value="4">4
      <input type="radio" name="skating" value="5">5

      <input type="radio" name="skating" value="6">6
      <input type="radio" name="skating" value="7">7
      <input type="radio" name="skating" value="8">8
      <input type="radio" name="skating" value="9">9
      <input type="radio" name="skating" value="10">10
    </form>

    <form action="">
      <input type="radio" name="shooting" value="1">1
      <input type="radio" name="shooting" value="2">2
      <input type="radio" name="shooting" value="3">3
      <input type="radio" name="shooting" value="4">4
      <input type="radio" name="shooting" value="5">5

      <input type="radio" name="shooting" value="6">6
      <input type="radio" name="shooting" value="7">7
      <input type="radio" name="shooting" value="8">8
      <input type="radio" name="shooting" value="9">9
      <input type="radio" name="shooting" value="10">10
    </form>

    <form action="">
      <input type="radio" name="passing" value="1">1
      <input type="radio" name="passing" value="2">2
      <input type="radio" name="passing" value="3">3
      <input type="radio" name="passing" value="4">4
      <input type="radio" name="passing" value="5">5

      <input type="radio" name="passing" value="6">6
      <input type="radio" name="passing" value="7">7
      <input type="radio" name="passing" value="8">8
      <input type="radio" name="passing" value="9">9
      <input type="radio" name="passing" value="10">10
    </form>

    <form action="">
      <input type="radio" name="puck_control" value="1">1
      <input type="radio" name="puck_control" value="2">2
      <input type="radio" name="puck_control" value="3">3
      <input type="radio" name="puck_control" value="4">4
      <input type="radio" name="puck_control" value="5">5

      <input type="radio" name="puck_control" value="6">6
      <input type="radio" name="puck_control" value="7">7
      <input type="radio" name="puck_control" value="8">8
      <input type="radio" name="puck_control" value="9">9
      <input type="radio" name="puck_control" value="10">10
    </form>

    <form action="">
      <input type="radio" name="team_play" value="1">1
      <input type="radio" name="team_play" value="2">2
      <input type="radio" name="team_play" value="3">3
      <input type="radio" name="team_play" value="4">4
      <input type="radio" name="team_play" value="5">5

      <input type="radio" name="team_play" value="6">6
      <input type="radio" name="team_play" value="7">7
      <input type="radio" name="team_play" value="8">8
      <input type="radio" name="team_play" value="9">9
      <input type="radio" name="team_play" value="10">10
    </form>

    <form action="">
      <input type="radio" name="attendance" value="1">1
      <input type="radio" name="attendance" value="2">2
      <input type="radio" name="attendance" value="3">3
      <input type="radio" name="attendance" value="4">4
      <input type="radio" name="attendance" value="5">5

      <input type="radio" name="attendance" value="6">6
      <input type="radio" name="attendance" value="7">7
      <input type="radio" name="attendance" value="8">8
      <input type="radio" name="attendance" value="9">9
      <input type="radio" name="attendance" value="10">10
    </form>

  <input type="button" onclick="tableToExcel('copyTable', 'Player_scores')" value="Export to Excel">

Body:
The problem is caused by <br> tags in the table cells. Remove them when preparing the export as I do below. Another option is excluding <br> from the HTML.

Also you can omit <form> tags. And the better practice is to use <label> instead of <span> like this: <label><input type="radio" name="skating" value="1">1</label>.

Good luck!

 var overall= $('#overall');

    $(document).ready(function() {
      $(':radio').change(function(e) {
        var row = $(this).closest('.item');
        var checkedItems = row.find(":checked:not(:radio[name='attendance'])")
      if(e.target.name != "attendance"){

        if (checkedItems.length == 5) {
          row.find("td.overall").html(getOverall(checkedItems));
        }
      }else{
        row.find("td.attendance").html("x "+parseFloat($(this).val()/10).toFixed(1));
      }
    })

    function getOverall(_checkedItems) {
    var total = 0;
    _checkedItems.each(function() {
    total += parseFloat($(this).val());
    });
    return total;
    }

    });

var tableToExcel = (function() {

  var uri = 'data:application/vnd.ms-excel;base64,',
    template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}<\/x:Name><x:WorksheetOptions><x:DisplayGridlines/><\/x:WorksheetOptions><\/x:ExcelWorksheet><\/x:ExcelWorksheets><\/x:ExcelWorkbook><\/xml><![endif]--><\/head><body><table>{table}<\/table><\/body><\/html>',
    base64 = function(s) {
      return window.btoa(unescape(encodeURIComponent(s)))
    },
    format = function(s, c) {
      return s.replace(/{(\w+)}/g, function(m, p) {
        return c[p];
      })
    }
  return function(table, name) {
    if (!table.nodeType) {
    table = document.getElementById(table)}
    var cloned = $('#copyTable').clone().appendTo('.hidden_table')
    cloned.find('input[type="radio"]:not(:checked) + span').remove()
    .end().find('br').remove();

    var ctx = {
      worksheet: name || 'Worksheet',
      table: cloned.html()
    }
    cloned.remove();
    window.location.href = uri + base64(format(template, ctx));
  }
})();

table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 115%;
}

td,
th {
  border: 1px solid #dddddd;
  text-align: center;
}

tr:nth-child(even) {
  background-color: #dddddd;
}

.hidden_table{
/*display:none*/
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="copyTable">
  <thead>
    <tr>
  <th>Team</th>
  <th>Player</th>
  <th>Number</th>
  <th>Position</th>
  <th>Skating</th>
  <th>Shooting</th>
  <th>Passing</th>
  <th>Puck Control</th>
  <th>Game Understanding</th>
  <th>Attendance</th>
  <th>Overall</th>
  <th>Attendance Factor</th>
    </tr>
  </thead>
  <tbody>
<tr class="item" data-id="1">
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td>
    <form action="">
      <input type="radio" name="skating" value="1"><span>1</span>
      <input type="radio" name="skating" value="2"><span>2</span>
      <input type="radio" name="skating" value="3"><span>3</span>
      <input type="radio" name="skating" value="4"><span>4</span>
      <input type="radio" name="skating" value="5"><span>5</span>
      <br>
      <input type="radio" name="skating" value="6"><span>6</span>
      <input type="radio" name="skating" value="7"><span>7</span>
      <input type="radio" name="skating" value="8"><span>8</span>
      <input type="radio" name="skating" value="9"><span>9</span>
      <input type="radio" name="skating" value="10"><span>10</span>
    </form>
  </td>
  <td>
    <form action="">
      <input type="radio" name="shooting" value="1"><span>1</span>
      <input type="radio" name="shooting" value="2"><span>2</span>
      <input type="radio" name="shooting" value="3"><span>3</span>
      <input type="radio" name="shooting" value="4"><span>4</span>
      <input type="radio" name="shooting" value="5"><span>5</span>
      <br>
      <input type="radio" name="shooting" value="6"><span>6</span>
      <input type="radio" name="shooting" value="7"><span>7</span>
      <input type="radio" name="shooting" value="8"><span>8</span>
      <input type="radio" name="shooting" value="9"><span>9</span>
      <input type="radio" name="shooting" value="10"><span>10</span>
    </form>
  </td>
  <td>
    <form action="">
      <input type="radio" name="passing" value="1"><span>1</span>
      <input type="radio" name="passing" value="2"><span>2</span>
      <input type="radio" name="passing" value="3"><span>3</span>
      <input type="radio" name="passing" value="4"><span>4</span>
      <input type="radio" name="passing" value="5"><span>5</span>
      <br>
      <input type="radio" name="passing" value="6"><span>6</span>
      <input type="radio" name="passing" value="7"><span>7</span>
      <input type="radio" name="passing" value="8"><span>8</span>
      <input type="radio" name="passing" value="9"><span>9</span>
      <input type="radio" name="passing" value="10"><span>10</span>
    </form>
  </td>
  <td>
    <form action="">
      <input type="radio" name="puck_control" value="1"><span>1</span>
      <input type="radio" name="puck_control" value="2"><span>2</span>
      <input type="radio" name="puck_control" value="3"><span>3</span>
      <input type="radio" name="puck_control" value="4"><span>4</span>
      <input type="radio" name="puck_control" value="5"><span>5</span>
      <br>
      <input type="radio" name="puck_control" value="6"><span>6</span>
      <input type="radio" name="puck_control" value="7"><span>7</span>
      <input type="radio" name="puck_control" value="8"><span>8</span>
      <input type="radio" name="puck_control" value="9"><span>9</span>
      <input type="radio" name="puck_control" value="10"><span>10</span>
    </form>
  </td>
  <td>
    <form action="">
      <input type="radio" name="team_play" value="1"><span>1</span>
      <input type="radio" name="team_play" value="2"><span>2</span>
      <input type="radio" name="team_play" value="3"><span>3</span>
      <input type="radio" name="team_play" value="4"><span>4</span>
      <input type="radio" name="team_play" value="5"><span>5</span>
      <br>
      <input type="radio" name="team_play" value="6"><span>6</span>
      <input type="radio" name="team_play" value="7"><span>7</span>
      <input type="radio" name="team_play" value="8"><span>8</span>
      <input type="radio" name="team_play" value="9"><span>9</span>
      <input type="radio" name="team_play" value="10"><span>10</span>
    </form>
  </td>
  <td>
    <form action="">
      <input type="radio" name="attendance" value="1"><span>1</span>
      <input type="radio" name="attendance" value="2"><span>2</span>
      <input type="radio" name="attendance" value="3"><span>3</span>
      <input type="radio" name="attendance" value="4"><span>4</span>
      <input type="radio" name="attendance" value="5"><span>5</span>
      <br>
      <input type="radio" name="attendance" value="6"><span>6</span>
      <input type="radio" name="attendance" value="7"><span>7</span>
      <input type="radio" name="attendance" value="8"><span>8</span>
      <input type="radio" name="attendance" value="9"><span>9</span>
      <input type="radio" name="attendance" value="10"><span>10</span>
    </form>
  </td>
  <td class="overall" id="overall">
  </td>
  <td class="attendance" id="attendance"></td>

</tr>
<tr class="item" data-id="2">
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td>
    <form action="">
      <input type="radio" name="skating" value="1"><span>1</span>
      <input type="radio" name="skating" value="2"><span>2</span>
      <input type="radio" name="skating" value="3"><span>3</span>
      <input type="radio" name="skating" value="4"><span>4</span>
      <input type="radio" name="skating" value="5"><span>5</span>
      <br>
      <input type="radio" name="skating" value="6"><span>6</span>
      <input type="radio" name="skating" value="7"><span>7</span>
      <input type="radio" name="skating" value="8"><span>8</span>
      <input type="radio" name="skating" value="9"><span>9</span>
      <input type="radio" name="skating" value="10"><span>10</span>
    </form>
  </td>
  <td>
    <form action="">
      <input type="radio" name="shooting" value="1"><span>1</span>
      <input type="radio" name="shooting" value="2"><span>2</span>
      <input type="radio" name="shooting" value="3"><span>3</span>
      <input type="radio" name="shooting" value="4"><span>4</span>
      <input type="radio" name="shooting" value="5"><span>5</span>
      <br>
      <input type="radio" name="shooting" value="6"><span>6</span>
      <input type="radio" name="shooting" value="7"><span>7</span>
      <input type="radio" name="shooting" value="8"><span>8</span>
      <input type="radio" name="shooting" value="9"><span>9</span>
      <input type="radio" name="shooting" value="10"><span>10</span>
    </form>
  </td>
  <td>
    <form action="">
      <input type="radio" name="passing" value="1"><span>1</span>
      <input type="radio" name="passing" value="2"><span>2</span>
      <input type="radio" name="passing" value="3"><span>3</span>
      <input type="radio" name="passing" value="4"><span>4</span>
      <input type="radio" name="passing" value="5"><span>5</span>
      <br>
      <input type="radio" name="passing" value="6"><span>6</span>
      <input type="radio" name="passing" value="7"><span>7</span>
      <input type="radio" name="passing" value="8"><span>8</span>
      <input type="radio" name="passing" value="9"><span>9</span>
      <input type="radio" name="passing" value="10"><span>10</span>
    </form>
  </td>
  <td>
    <form action="">
      <input type="radio" name="puck_control" value="1"><span>1</span>
      <input type="radio" name="puck_control" value="2"><span>2</span>
      <input type="radio" name="puck_control" value="3"><span>3</span>
      <input type="radio" name="puck_control" value="4"><span>4</span>
      <input type="radio" name="puck_control" value="5"><span>5</span>
      <br>
      <input type="radio" name="puck_control" value="6"><span>6</span>
      <input type="radio" name="puck_control" value="7"><span>7</span>
      <input type="radio" name="puck_control" value="8"><span>8</span>
      <input type="radio" name="puck_control" value="9"><span>9</span>
      <input type="radio" name="puck_control" value="10"><span>10</span>
    </form>
  </td>
  <td>
    <form action="">
      <input type="radio" name="team_play" value="1"><span>1</span>
      <input type="radio" name="team_play" value="2"><span>2</span>
      <input type="radio" name="team_play" value="3"><span>3</span>
      <input type="radio" name="team_play" value="4"><span>4</span>
      <input type="radio" name="team_play" value="5"><span>5</span>
      <br>
      <input type="radio" name="team_play" value="6"><span>6</span>
      <input type="radio" name="team_play" value="7"><span>7</span>
      <input type="radio" name="team_play" value="8"><span>8</span>
      <input type="radio" name="team_play" value="9"><span>9</span>
      <input type="radio" name="team_play" value="10"><span>10</span>
    </form>
  </td>
  <td>
    <form action="">
      <input type="radio" name="attendance" value="1"><span>1</span>
      <input type="radio" name="attendance" value="2"><span>2</span>
      <input type="radio" name="attendance" value="3"><span>3</span>
      <input type="radio" name="attendance" value="4"><span>4</span>
      <input type="radio" name="attendance" value="5"><span>5</span>
      <br>
      <input type="radio" name="attendance" value="6"><span>6</span>
      <input type="radio" name="attendance" value="7"><span>7</span>
      <input type="radio" name="attendance" value="8"><span>8</span>
      <input type="radio" name="attendance" value="9"><span>9</span>
      <input type="radio" name="attendance" value="10"><span>10</span>
    </form>
  </td>
  <td class="overall" id="overall">
  </td>
  <td class="attendance" id="attendance"></td>

</tr>
  </tbody>
</table>
<div class="hidden_table" id="hidden_table"></div>
<div align="center">
  <input type="button" onclick="tableToExcel('copyTable', 'Player_scores')" value="Export to Excel">
</div>


来源: stackexchange

问:
Generating a recursive sitemap with relative href links
I'm using Flask to expose a local directory of HTML files on a web page.

I am also using a jinja2 to generate the sitemap in the lefthand div of my main endpoint.

I am unable to correctly specify the URL to the endpoint of my subfolders.

As mentioned in the code below, how would I dynamically build a relative link from /docs (i.e. /docs/folder1/subfolder1/SubFolder1Page.html)?
The way I am currently setting the value for href obviously does not work.

```<code><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Docs Demo</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
    <div id="container">
        <div class="left_frame">
            <h1>{{ tree.name }}</h1>
            <ul>
            {%- for item in tree.children recursive %}
                <!-- How would I build a relative link from /docs/ i.e. /docs/folder1/subfolder1/SubFolder1Page.html -->
                <li><a href="docs/{{ item.name }}" target="iframe1">{{ item.name }}
                {%- if item.children -%}
                    <ul>{{ loop(item.children) }}</ul>
                {%- endif %}</a></li>
            {%- endfor %}
            </ul>
        </div>
        <div class="right_frame">
            <iframe name="iframe1"></iframe>
        </div>
    </div>
</body>
</html>
</code>```

Folder structure example:

How it looks overall displaying the contents of file1.html:

答:
So I figured out a satisfying way of solving my own issue.

I managed to get this very functional result:

Do note that my template is only good for files with .html extension, though it can be easily enhanced to support other file extensions.

Here is my finalized templates\template.html file:

```<code><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Docs Demo</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
    <div id="container">
        <div class="left_frame">
            <h1>{{ tree.name }}</h1>
            <ul>
            {%- for item in tree.children recursive %}
                {% if '.html' in item.name %}
                    <li><a href="docs/{{ item.name }}" target="iframe1">
                    {{ item.name.split('/')[-1:][0] }}
                    {%- if item.children -%}
                        <ul>{{ loop(item.children) }}</ul>
                    {%- endif %}</a></li>
                {% else %}
                    <li>{{ item.name }}
                    {%- if item.children -%}
                        <ul>{{ loop(item.children) }}</ul>
                    {%- endif %}</li>
                {% endif %}
            {%- endfor %}
            </ul>
        </div>
        <div class="right_frame">
            <iframe name="iframe1"></iframe>
        </div>
    </div>
</body>
</html>
</code>```

You can refer to King Reload's answer for an analysis of what I've changed in the template.html file to make this work correctly.

And here is the demo_app.py script that serves my document HTML files via Flask:

```<code>import threading
import os
import webbrowser
from flask import Flask, render_template, send_from_directory

app = Flask(__name__, static_folder='static')

ROOT = os.path.dirname(os.path.abspath(__file__))
DOCS_ROOT = os.path.join(app.static_folder, 'docs')

@app.route('/')
def docs_tree():
    return render_template('template.html', tree=make_tree(DOCS_ROOT))

@app.route('/docs/<path:filename>')
def send_docs(filename):
    return send_from_directory(directory=DOCS_ROOT, 'docs'), filename=filename)

def make_tree(path):
    tree = dict(name=os.path.basename(path), children=[])
    try:
        lst = os.listdir(path)
    except OSError:
        pass  # ignore errors
    else:
        for name in lst:
            fn = os.path.join(path, name)
            if os.path.isdir(fn):
                tree['children'].append(make_tree(fn))
            else:
                np = os.path.join(path.replace(DOCS_ROOT, ''), name).replace('\\', '/')
                if np.startswith('/'):
                    np = np[1:]
                tree['children'].append(dict(name=np))
    return tree

if __name__ == '__main__':
    host = 'localhost'
    port = '8888'
    url = 'http://{h}:{p}'.format(h=host, p=port)
    threading.Timer(3, lambda: webbrowser.open(url)).start()
    app.run(host=host, port=port, debug=False)
</code>```

Most notable changes in demo_app.py since asking my original question were the following:

After initializing app, I set DOCS_ROOT using app.static_folder;

In the function send_docs(), I changed the send_from_directory()'s directory argument to use DOCS_ROOT;

Inside of make_tree(), inside the else block of the for loop, I added:

```<code>np = os.path.join(path.replace(DOCS_ROOT, ''), name).replace('\\', '/')
if np.startswith('/'):
    np = np[1:]
</code>```

All this does is take the absolute path of name, remove what matches DOCS_ROOT, leaving only the relative path (and then replacing the \\ for /), resulting in a simple relative path from static/docs. If the relative path starts with a /, I remove it (since there is a trailing / from docs in template.html.

For anyone interested in the simplistic stylesheet (static\styles.css) I used (along with some updated enhancements):

```<code>html {
    min-height:100%;
    position:relative;
}

body {
    overflow:hidden;
}

.container {
    width:100%;
    overflow:auto;
}

.left_frame {
    float:left;
    background:#E8F1F5;
    width:25%;
    height:100vh;
}

.right_frame {
    float:right;
    background:#FAFAFA;
    width:75%;
    height:100vh;
}

.right_frame iframe {
    display:block;
    width:100%;
    height:100%;
    border:none;
}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I'm using Flask to expose a local directory of HTML files on a web page.

I am also using a jinja2 to generate the sitemap in the lefthand div of my main endpoint.

I am unable to correctly specify the URL to the endpoint of my subfolders.

As mentioned in the code below, how would I dynamically build a relative link from /docs (i.e. /docs/folder1/subfolder1/SubFolder1Page.html)?
The way I am currently setting the value for href obviously does not work.

<!DOCTYPE html>

    <meta charset="UTF-8">
    <title>Docs Demo</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">

{{ tree.name }}

            {%- for item in tree.children recursive %}

{{ item.name }}
                {%- if item.children -%}

{{ loop(item.children) }}

                {%- endif %}

            {%- endfor %}

Folder structure example:

How it looks overall displaying the contents of file1.html:

Body:
So I figured out a satisfying way of solving my own issue.

I managed to get this very functional result:

Do note that my template is only good for files with .html extension, though it can be easily enhanced to support other file extensions.

Here is my finalized templates\template.html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Docs Demo</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
    <div id="container">
        <div class="left_frame">
            <h1>{{ tree.name }}</h1>
            <ul>
            {%- for item in tree.children recursive %}
                {% if '.html' in item.name %}
                    <li><a href="docs/{{ item.name }}" target="iframe1">
                    {{ item.name.split('/')[-1:][0] }}
                    {%- if item.children -%}
                        <ul>{{ loop(item.children) }}</ul>
                    {%- endif %}</a></li>
                {% else %}
                    <li>{{ item.name }}
                    {%- if item.children -%}
                        <ul>{{ loop(item.children) }}</ul>
                    {%- endif %}</li>
                {% endif %}
            {%- endfor %}
            </ul>
        </div>
        <div class="right_frame">
            <iframe name="iframe1"></iframe>
        </div>
    </div>
</body>
</html>

You can refer to King Reload's answer for an analysis of what I've changed in the template.html file to make this work correctly.

And here is the demo_app.py script that serves my document HTML files via Flask:

import threading
import os
import webbrowser
from flask import Flask, render_template, send_from_directory

app = Flask(__name__, static_folder='static')

ROOT = os.path.dirname(os.path.abspath(__file__))
DOCS_ROOT = os.path.join(app.static_folder, 'docs')

@app.route('/')
def docs_tree():
    return render_template('template.html', tree=make_tree(DOCS_ROOT))

@app.route('/docs/<path:filename>')
def send_docs(filename):
    return send_from_directory(directory=DOCS_ROOT, 'docs'), filename=filename)

def make_tree(path):
    tree = dict(name=os.path.basename(path), children=[])
    try:
        lst = os.listdir(path)
    except OSError:
        pass  # ignore errors
    else:
        for name in lst:
            fn = os.path.join(path, name)
            if os.path.isdir(fn):
                tree['children'].append(make_tree(fn))
            else:
                np = os.path.join(path.replace(DOCS_ROOT, ''), name).replace('\\', '/')
                if np.startswith('/'):
                    np = np[1:]
                tree['children'].append(dict(name=np))
    return tree

if __name__ == '__main__':
    host = 'localhost'
    port = '8888'
    url = 'http://{h}:{p}'.format(h=host, p=port)
    threading.Timer(3, lambda: webbrowser.open(url)).start()
    app.run(host=host, port=port, debug=False)

Most notable changes in demo_app.py since asking my original question were the following:

After initializing app, I set DOCS_ROOT using app.static_folder;

In the function send_docs(), I changed the send_from_directory()'s directory argument to use DOCS_ROOT;

Inside of make_tree(), inside the else block of the for loop, I added:

np = os.path.join(path.replace(DOCS_ROOT, ''), name).replace('\\', '/')
if np.startswith('/'):
    np = np[1:]

All this does is take the absolute path of name, remove what matches DOCS_ROOT, leaving only the relative path (and then replacing the \\ for /), resulting in a simple relative path from static/docs. If the relative path starts with a /, I remove it (since there is a trailing / from docs in template.html.

For anyone interested in the simplistic stylesheet (static\styles.css) I used (along with some updated enhancements):

html {
    min-height:100%;
    position:relative;
}

body {
    overflow:hidden;
}

.container {
    width:100%;
    overflow:auto;
}

.left_frame {
    float:left;
    background:#E8F1F5;
    width:25%;
    height:100vh;
}

.right_frame {
    float:right;
    background:#FAFAFA;
    width:75%;
    height:100vh;
}

.right_frame iframe {
    display:block;
    width:100%;
    height:100%;
    border:none;
}


问:
Temporal Tables - "Parameterise" extended SYSTEM_TIME syntax
```<code>    SELECT *
    FROM Spine    S
    CROSS
    APPLY
    (
        SELECT *
        FROM PersonTemporalTable
        FOR SYSTEM_TIME AS OF S.DateTimeValueOfInterest
    )            CA
</code>```

It would be much simpler if I left out the "why" of it and stuck to the "what" and "how".
I need to be be able to query a Temporal table for record state at specific points in time - were the syntax above legal, it would do precisely what I am after.
In this case, the table Spine contains a list of DATETIME values of interest.

Is this simply a matter of not using the correct syntax or is it a limitation?
Besides going with dynamic SQL, do you guys have any other suggestions I could try?

Thanks in advance!

This is what I landed up doing, based on suggestions by @SQLZim

```<code>SELECT *
FROM Spine      SP
JOIN PetTemporal    FOR SYSTEM_TIME ALL PT  ON  SP.SpineDT >= PT.ValidFrom AND SP.SpineDT < PT.ValidTo
JOIN PersonTemporal FOR SYSTEM_TIME ALL PS  ON  SP.SpineDT >= PS.ValidFrom AND SP.SpineDT < PS.ValidTo
                                            AND PS.PersonID = PT.PersonID
</code>```

答:
If you want to return Spine rows even if there is no corresponding row in PersonTemporalTable, switch to outer apply().

If PersonTemporalTable contains an effective date range:

```<code>select *
from Spine S
  cross apply (
    select ptt.*
    from PersonTemporalTable
    where ptt.FromDateTime <= S.DateTimeValueOfInterest
      and ptt.ThruDateTime >= S.DateTimeValueOfInterest
  ) CA
</code>```

If PersonTemporalTable contains a single effective date:

```<code>select *
from Spine S
  cross apply (
    select top 1 ptt.*
    from PersonTemporalTable ptt
    where ptt.EffectiveDate <= S.DateTimeValueOfInterest
  order by ptt.EffectiveDate desc
  ) CA
</code>```

If this is supposed to return rows where the two tables share a corresponding key, e.g. PersonId, then include that in the where of the cross apply(), e.g.:

```<code>select *
from Spine S
  cross apply (
    select top 1 ptt.*
    from PersonTemporalTable ptt
    where ptt.EffectiveDate <= S.DateTimeValueOfInterest
      and ptt.PersonId = S.PersonId
  order by ptt.EffectiveDate desc
  ) CA
</code>```

Another option that takes advantage of the extended system_time as of syntax: you could create an inline table-valued function to use with cross apply() like so:

```<code>create function dbo.PersonTemporalTable_AsOf (@fromdate datetime2(7)) returns table as return (
select *
  from PersonTemporalTable
  for system_time as of @fromdate
)
go
select *
from spine s
  cross apply dbo.PersonTemporalTable_AsOf(s.DateTimeValueOfInterest) ca
</code>```

dbfiddle.uk demo: http://dbfiddle.uk/?rdbms=sqlserver_2016&fiddle=f1ee20893fe987e71cbd0cb12d09fccb

Body:
    SELECT *
    FROM Spine    S
    CROSS
    APPLY
    (
        SELECT *
        FROM PersonTemporalTable
        FOR SYSTEM_TIME AS OF S.DateTimeValueOfInterest
    )            CA

It would be much simpler if I left out the "why" of it and stuck to the "what" and "how".
I need to be be able to query a Temporal table for record state at specific points in time - were the syntax above legal, it would do precisely what I am after.
In this case, the table Spine contains a list of DATETIME values of interest.

Is this simply a matter of not using the correct syntax or is it a limitation?
Besides going with dynamic SQL, do you guys have any other suggestions I could try?

Thanks in advance!

This is what I landed up doing, based on suggestions by @SQLZim

SELECT *
FROM Spine      SP
JOIN PetTemporal    FOR SYSTEM_TIME ALL PT  ON  SP.SpineDT >= PT.ValidFrom AND SP.SpineDT < PT.ValidTo
JOIN PersonTemporal FOR SYSTEM_TIME ALL PS  ON  SP.SpineDT >= PS.ValidFrom AND SP.SpineDT < PS.ValidTo
                                            AND PS.PersonID = PT.PersonID

Body:
If you want to return Spine rows even if there is no corresponding row in PersonTemporalTable, switch to outer apply().

If PersonTemporalTable contains an effective date range:

select *
from Spine S
  cross apply (
    select ptt.*
    from PersonTemporalTable
    where ptt.FromDateTime <= S.DateTimeValueOfInterest
      and ptt.ThruDateTime >= S.DateTimeValueOfInterest
  ) CA

If PersonTemporalTable contains a single effective date:

select *
from Spine S
  cross apply (
    select top 1 ptt.*
    from PersonTemporalTable ptt
    where ptt.EffectiveDate <= S.DateTimeValueOfInterest
  order by ptt.EffectiveDate desc
  ) CA

If this is supposed to return rows where the two tables share a corresponding key, e.g. PersonId, then include that in the where of the cross apply(), e.g.:

select *
from Spine S
  cross apply (
    select top 1 ptt.*
    from PersonTemporalTable ptt
    where ptt.EffectiveDate <= S.DateTimeValueOfInterest
      and ptt.PersonId = S.PersonId
  order by ptt.EffectiveDate desc
  ) CA

Another option that takes advantage of the extended system_time as of syntax: you could create an inline table-valued function to use with cross apply() like so:

create function dbo.PersonTemporalTable_AsOf (@fromdate datetime2(7)) returns table as return (
select *
  from PersonTemporalTable
  for system_time as of @fromdate
)
go
select *
from spine s
  cross apply dbo.PersonTemporalTable_AsOf(s.DateTimeValueOfInterest) ca

dbfiddle.uk demo: http://dbfiddle.uk/?rdbms=sqlserver_2016&fiddle=f1ee20893fe987e71cbd0cb12d09fccb


问:
javascript on click image src change
I want to code that when I click on a image the src of this image changes to another src. But it doesn't work. Can someone help me?</p>

```<code><?php require_once("php/config.php"); ?>
<!DOCTYPE html>
<html>
<head>
<title> test </title>
<script type="text/javascript" src="javascript/liabary.js"></script>
</head>
    <body>
        <img id="img" onclick="next()" src="img/bildergalerie/bild3.jpg" id="b3" width="1000" height="500" alt="image" />
        <script type="text/javascript">

        function next() {
            var img = document.getElementByIdName("img");
            img.src = "image2.jpg";
        }
        </script>
    </body>
</html>
</code>```

答:
getElementsByClassName returns an array-like object, so you need to refer to the specific one you want. For example img[0].src = "image2.jpg";

jsFiddle example

Or, instead of looking for the class, you can use the id instead:

```<code>var img = document.querySelector("#b3");
</code>```

or

```<code>var img = document.getElementById("b3");
</code>```

This will only return one element, which then you can reference in the way you did.

ContentLicense: CC BY-SA 4.0

Title: javascript on click image src change

Body:
I want to code that when I click on a image the src of this image changes to another src. But it doesn't work. Can someone help me?

<?php require_once("php/config.php"); ?>
<!DOCTYPE html>

<title> test </title>

Body:
getElementsByClassName returns an array-like object, so you need to refer to the specific one you want. For example img[0].src = "image2.jpg";

jsFiddle example

Or, instead of looking for the class, you can use the id instead:

var img = document.querySelector("#b3");

or

var img = document.getElementById("b3");

This will only return one element, which then you can reference in the way you did.


问:
Invalid route in a Laravel search form
Hi i'm following a tutorial bout how to set a search form but I'm getting a route error (NotFoundHttpException).

form

```<code>   {!! Form::open(['method'=>'GET' ,'url' => 'search', 'class'=>'form-group main-form', 'id'=>'search-form', 'role'=>'form']) !!}
      {{ csrf_field() }}
      <div style="display:none"><input name="utf8" type="hidden" value="✓"></div>
      <input class="form-group main-form" id="q_objname_en_cont" name="searchKey"  placeholder='Search by Job title' required="required" style="height:40px;width:60%" type="search">
      <input class="btn btn-warning" type="submit" value="Search">
   {!! Form::close() !!}
</code>```

Route

```<code>//Search route(get)
Route::get('search/{searchkey}', 'EmploiController@search')->where('searchkey', '[A-Za-z]+')->name('search');
</code>```

url (browser)

```<code>http://localhost:8000/search?_token=LJpgN3AwCFoDElOkFsSOX8BBLU1IFOzMvUYiokQj&utf8=%E2%9C%93&searchKey=quia
</code>```

答:
Change your route to this. You don't need the second part of url when you're passing the search parameters as the query string.

```<code>Route::get('search', 'EmploiController@search')->name('search');
</code>```

Change your form to this. You don't need to send the csrf token when you're using form GET method.

```<code>{!! Form::open(['method'=>'GET' ,'url' => 'search', 'class'=>'form-group main-form', 'id'=>'search-form', 'role'=>'form']) !!}
<input class="form-group main-form" id="q_objname_en_cont" name="searchKey"  placeholder='Search by Job title' required="required" style="height:40px;width:60%" type="search">
<input class="btn btn-warning" type="submit" value="Search">
{!! Form::close() !!}
</code>```

I've also removed the unwanted input <input name="utf8" type="hidden" value="✓">. Add it back if it was intended.

Title: Invalid route in a Laravel search form

Body:
Hi i'm following a tutorial bout how to set a search form but I'm getting a route error (NotFoundHttpException).

form

   {!! Form::open(['method'=>'GET' ,'url' => 'search', 'class'=>'form-group main-form', 'id'=>'search-form', 'role'=>'form']) !!}
      {{ csrf_field() }}

<input name="utf8" type="hidden" value="✓">

      <input class="form-group main-form" id="q_objname_en_cont" name="searchKey"  placeholder='Search by Job title' required="required" style="height:40px;width:60%" type="search">
      <input class="btn btn-warning" type="submit" value="Search">
   {!! Form::close() !!}

Route

//Search route(get)
Route::get('search/{searchkey}', 'EmploiController@search')->where('searchkey', '[A-Za-z]+')->name('search');

url (browser)

http://localhost:8000/search?_token=LJpgN3AwCFoDElOkFsSOX8BBLU1IFOzMvUYiokQj&utf8=%E2%9C%93&searchKey=quia

Body:
Change your route to this. You don't need the second part of url when you're passing the search parameters as the query string.

Route::get('search', 'EmploiController@search')->name('search');

Change your form to this. You don't need to send the csrf token when you're using form GET method.

{!! Form::open(['method'=>'GET' ,'url' => 'search', 'class'=>'form-group main-form', 'id'=>'search-form', 'role'=>'form']) !!}
<input class="form-group main-form" id="q_objname_en_cont" name="searchKey"  placeholder='Search by Job title' required="required" style="height:40px;width:60%" type="search">
<input class="btn btn-warning" type="submit" value="Search">
{!! Form::close() !!}

I've also removed the unwanted input <input name="utf8" type="hidden" value="✓">. Add it back if it was intended.


问:
If you multiply the smallest positive floating point value by a non-zero number, are you guaranteed a non-zero result?
If I take epsilon to be the smallest positive non-zero floating point number (be it 16, 32, or 64 bit) and multiply epsilon by a non-zero floating point value of the same size:

Am I guaranteed a non-zero result of the same sign as the original
  value? Or do I risk rounding error (zero, or switching signs)?

Environment: Python/Numpy

答:
No.

```<code>In [1]: import numpy

In [2]: x = numpy.nextafter(0, 1)

In [3]: x
Out[3]: 4.9406564584124654e-324

In [4]: x*x
Out[4]: 0.0
</code>```

When the exact result is between 0 and the smallest positive float, it has to round to one of those options, and in this case, 0 is closer.

If for some reason you want to customize this behavior, NumPy lets you customize the behavior of underflow and other IEEE 754 floating-point exceptions with numpy.seterr, although it won't affect operations on ordinary Python objects:

```<code>In [5]: numpy.seterr(under='raise')
Out[5]: {'divide': 'warn', 'invalid': 'warn', 'over': 'warn', 'under': 'ignore'}

In [6]: x # NumPy float, not regular float, despite its looks
Out[6]: 4.9406564584124654e-324

In [7]: x*x
---------------------------------------------------------------------------
FloatingPointError                        Traceback (most recent call last)
<ipython-input-7-a3ff2a28c75d> in <module>()
----> 1 x*x

FloatingPointError: underflow encountered in double_scalars

In [8]: (4.9406564584124654e-324)**2 # regular float
Out[8]: 0.0
</code>```

There's no way to change the rounding mode.

Body:
No.

In [1]: import numpy

In [2]: x = numpy.nextafter(0, 1)

In [3]: x
Out[3]: 4.9406564584124654e-324

In [4]: x*x
Out[4]: 0.0

When the exact result is between 0 and the smallest positive float, it has to round to one of those options, and in this case, 0 is closer.

If for some reason you want to customize this behavior, NumPy lets you customize the behavior of underflow and other IEEE 754 floating-point exceptions with numpy.seterr, although it won't affect operations on ordinary Python objects:

In [5]: numpy.seterr(under='raise')
Out[5]: {'divide': 'warn', 'invalid': 'warn', 'over': 'warn', 'under': 'ignore'}

In [6]: x # NumPy float, not regular float, despite its looks
Out[6]: 4.9406564584124654e-324

In [7]: x*x
---------------------------------------------------------------------------
FloatingPointError                        Traceback (most recent call last)
<ipython-input-7-a3ff2a28c75d> in <module>()
----> 1 x*x

FloatingPointError: underflow encountered in double_scalars

In [8]: (4.9406564584124654e-324)**2 # regular float
Out[8]: 0.0

There's no way to change the rounding mode.


问:
Scala: short form of pattern matching that returns Boolean
I found myself writing something like this quite often:

```<code>a match {
  case `b` => // do stuff
  case _ => // do nothing
}
</code>```

Is there a shorter way to check if some value matches a pattern? I mean, in this case I could just write if (a == b) // do stuff, but what if the pattern is more complex? Like when matching against a list or any pattern of arbitrary complexity. I'd like to be able to write something like this:

```<code>if (a matches b) // do stuff
</code>```

I'm relatively new to Scala, so please pardon, if I'm missing something big :)

答:
The best I can come up with is this:

```<code>def matches[A](a:A)(f:PartialFunction[A, Unit]) = f.isDefinedAt(a)

if (matches(a){case ... =>}) {
    //do stuff
}
</code>```

This won't win you any style points though.

Body:
I found myself writing something like this quite often:

a match {
  case `b` => // do stuff
  case _ => // do nothing
}

Is there a shorter way to check if some value matches a pattern? I mean, in this case I could just write if (a == b) // do stuff, but what if the pattern is more complex? Like when matching against a list or any pattern of arbitrary complexity. I'd like to be able to write something like this:

if (a matches b) // do stuff

I'm relatively new to Scala, so please pardon, if I'm missing something big :)

Body:
The best I can come up with is this:

def matches[A](a:A)(f:PartialFunction[A, Unit]) = f.isDefinedAt(a)

if (matches(a){case ... =>}) {
    //do stuff
}

This won't win you any style points though.

ContentLicense: CC BY-SA 2.5


问:
Java copy + user input word program with stupid results
Just tried to create a program that lets the user put a word that will appear in a new .txt file every 3 words. Here goes the code:

```<code>public static void main(String[] args) {

    if(args.length != 1){
        System.out.println("Wrong amount of files");
        return;
    }

    try(FileReader fr = new FileReader(args[0]); FileWriter fw = new FileWriter("lorem ipsum1.txt")){

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedReader br1 = new BufferedReader(fr);
        String str;
        char ch;
        int count = 0;
        str = br.readLine();

        do{
            ch = (char) br1.read();
            if(ch == ' '){
                count++;
            }
            else if(count == 3){
                fw.write(" " +str + ' ');
                count = 0;
            }
            else{
                fw.write(ch);
            }

        }while(br1.read() != -1);

    }catch(IOException exc){

    }

}
</code>```

Text is just a lorem ipsum. That's the outcome after putting word "word":

```<code>Lrmismdlrstae,cnettraiicnltiau word prlglttroolscnettri word prsupnisedei word lsmgaaiclsobdutiislgl.Di word rtasmnqeusmxmsjsoefctra.Cacusnmgai word
</code>```

How to fix this?

答:
You're calling br1.read() twice per loop, so it's dropping every second letter. Try this:

```<code>BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br1 = new BufferedReader(fr);
String str;
int r;
char ch;
int count = 0;
str = br.readLine();

while ((r = br1.read()) != -1) {
    ch = (char) r;
    if (ch == ' ') {
        count++;
    } else if (count == 3) {
        fw.write(" " + str + ' ');
        count = 0;
    } else {
        fw.write(ch);
    }
}
</code>```

Body:
Just tried to create a program that lets the user put a word that will appear in a new .txt file every 3 words. Here goes the code:

public static void main(String[] args) {

    if(args.length != 1){
        System.out.println("Wrong amount of files");
        return;
    }

    try(FileReader fr = new FileReader(args[0]); FileWriter fw = new FileWriter("lorem ipsum1.txt")){

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedReader br1 = new BufferedReader(fr);
        String str;
        char ch;
        int count = 0;
        str = br.readLine();

        do{
            ch = (char) br1.read();
            if(ch == ' '){
                count++;
            }
            else if(count == 3){
                fw.write(" " +str + ' ');
                count = 0;
            }
            else{
                fw.write(ch);
            }

        }while(br1.read() != -1);

    }catch(IOException exc){

    }

}

Text is just a lorem ipsum. That's the outcome after putting word "word":

Lrmismdlrstae,cnettraiicnltiau word prlglttroolscnettri word prsupnisedei word lsmgaaiclsobdutiislgl.Di word rtasmnqeusmxmsjsoefctra.Cacusnmgai word

How to fix this?

Body:
You're calling br1.read() twice per loop, so it's dropping every second letter. Try this:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br1 = new BufferedReader(fr);
String str;
int r;
char ch;
int count = 0;
str = br.readLine();

while ((r = br1.read()) != -1) {
    ch = (char) r;
    if (ch == ' ') {
        count++;
    } else if (count == 3) {
        fw.write(" " + str + ' ');
        count = 0;
    } else {
        fw.write(ch);
    }
}


问:
SQL - JOINing table ON a=b AND c=b?
I am building a query from multiple tables and ran into implementations of JOIN statements that I don't fully understand...

As an example, I have these tables:

```<code>Applications AS a      - columns(ID, MemberName)
ContractAHistory AS ca - columns(ID, AppID, PolicyNumber)
ContractBHistory AS cb - columns(ID, AppID, PolicyNumber)
MemberPolicy AS m      - columns(ID, PolicyNumber)
</code>```

And for clarity, there are two different kinds of Contracts (A and B) that each get assigned a PolicyNumber.

I would love to be able to do a query like this:

```<code>SELECT * FROM Applications a
FULL OUTER JOIN ContractAHistory ca ON a.ID=ca.AppID
FULL OUTER JOIN ContractBHistory cb ON a.ID=cb.AppID
FULL OUTER JOIN MemberPolicy m ON
    (ca.PolicyNumber=m.PolicyNumber AND cb.PolicyNumber=m.PolicyNumber)
WHERE m.PolicyNumber = 79301;
</code>```

This hasn't worked for me, however, so I have settled on this:

```<code>SELECT * FROM Applications a
FULL OUTER JOIN ContractAHistory ca ON a.ID=ca.AppID
FULL OUTER JOIN ContractBHistory cb ON a.ID=cb.AppID
FULL OUTER JOIN MemberPolicy m1 ON ca.PolicyNumber=m1.PolicyNumber
FULL OUTER JOIN MemberPolicy m2 ON ca.PolicyNumber=m2.PolicyNumber
WHERE m1.PolicyNumber = 79301 OR m2.PolicyNumber = 79301;
</code>```

Unfortunately, that means my WHERE clauses need to be more verbose:

```<code>... WHERE m1.PolicyNumber = 79301 OR m2.PolicyNumber = 79301;
</code>```

instead of

```<code>... WHERE m.PolicyNumber = 79301;
</code>```

Is it possible to achieve my ideal in this situation?  In the end, I desire to have the ability to use these all of these clean WHERE clauses on the properly constructed SQL query:

```<code>... WHERE a.MemberName = 'Annika Hansen';

... WHERE m.PolicyNumber = 79301;

... WHERE m.ID = 79;

... WHERE a.ID = 74656;
</code>```

I am using SQL-Server, but I have tried to phrase this as a general question about SQL. Please let me know if I have been unclear - thank you in advance!

Here is an example with undesired results (thanks to @TheEsisia for most of this:)

```<code>declare @Applications table (ID int, MemberName varchar(30))
declare @ContractAHistory table (ID int, AppID int, PolicyNumber varchar(30))
declare @ContractBHistory table (ID int, AppID int, PolicyNumber varchar(30))
declare @MemberPolicy table (ID int, PolicyNumber varchar(30))

Insert Into @Applications Values
 (1, 'AA')
,(2, 'BB')
,(3, 'CC')
,(4, 'DD')

Insert Into @ContractAHistory Values
  (1, 1, 'A')
 ,(2, 2, 'B')

Insert Into @ContractBHistory Values
 (1, 3, 'H12007')
,(2, 4, 'GT31')

Insert Into @MemberPolicy Values
 (1, 'A')
,(2, 'B')
,(3, 'H12007')
,(4, 'GT31')

SELECT * FROM @Applications a
FULL OUTER JOIN @ContractAHistory ca ON a.ID=ca.AppID
FULL OUTER JOIN @ContractBHistory cb ON a.ID=cb.AppID
FULL OUTER JOIN @MemberPolicy m ON
(ca.PolicyNumber=m.PolicyNumber AND cb.PolicyNumber=m.PolicyNumber)
WHERE m.PolicyNumber = 'GT31';
</code>```

Update: @TheEsisia helped me see that replacing the AND with an OR in the last query there achieves my desired results.  But answering @ThorstenKettner's questions: I certainly may not need all the FULL OUTER JOINs - however, I do want to pull up all information based on a specific WHERE clause. I can get requests for information with only one piece of the puzzle, so I'd like to pull up everything based on only an m.ID or an AppID or a PolicyNumber. For efficiency, I'm hoping to use the same primary query and only change the WHERE clause appropriately.  Also, each PolicyNumber matches to one Member and one Contract (either A or B) and one a.ID. That is where the complexity comes in: I never know from the PolicyNumber which kind of Contract it is. I hope that helps to clear up a bit about my use cases. Thanks to all.

答:
Here is how we should access the tables:

With a policy number we find the policy record.

Linked to that record is either an A contract record or a B contract record. So we must outer join these tables.

Then we want the application for the contract found. This can be done with an inner join, because we always expect a match. (We don't want contracts without a matching application entry. Or, in case we do, switch this to a left outer join)

The complete query:

```<code>SELECT *
FROM @MemberPolicy m
LEFT OUTER JOIN @ContractAHistory ca ON ca.PolicyNumber = m.PolicyNumber
LEFT OUTER JOIN @ContractBHistory cb ON cb.PolicyNumber = m.PolicyNumber
INNER JOIN @Applications a ON a.ID IN (ca.AppID, cb.AppID)
WHERE m.PolicyNumber = 'GT31';
</code>```

In case the contracts are very similar, you could also union the two tables. (But in that case it might be much better to change the database design and makes this one table only for the two contract types to start with.) In this situation we don't need any outer join; we select the policy, its contract and its application:

```<code>SELECT *
FROM @MemberPolicy m
INNER JOIN
(
  SELECT PolicyNumber, title, description, client, a_only_col, null as b_only_col
  FROM @ContractAHistory
  UNION ALL
  SELECT PolicyNumber, title, description, client, null as a_only_col, b_only_col
  FROM @ContractBHistory
) c ON c.PolicyNumber = m.PolicyNumber
INNER JOIN @Applications a ON a.ID = c.AppID
WHERE m.PolicyNumber = 'GT31';
</code>```

Title: SQL - JOINing table ON a=b AND c=b?

Body:
I am building a query from multiple tables and ran into implementations of JOIN statements that I don't fully understand...

As an example, I have these tables:

Applications AS a      - columns(ID, MemberName)
ContractAHistory AS ca - columns(ID, AppID, PolicyNumber)
ContractBHistory AS cb - columns(ID, AppID, PolicyNumber)
MemberPolicy AS m      - columns(ID, PolicyNumber)

And for clarity, there are two different kinds of Contracts (A and B) that each get assigned a PolicyNumber.

I would love to be able to do a query like this:

SELECT * FROM Applications a
FULL OUTER JOIN ContractAHistory ca ON a.ID=ca.AppID
FULL OUTER JOIN ContractBHistory cb ON a.ID=cb.AppID
FULL OUTER JOIN MemberPolicy m ON
    (ca.PolicyNumber=m.PolicyNumber AND cb.PolicyNumber=m.PolicyNumber)
WHERE m.PolicyNumber = 79301;

This hasn't worked for me, however, so I have settled on this:

SELECT * FROM Applications a
FULL OUTER JOIN ContractAHistory ca ON a.ID=ca.AppID
FULL OUTER JOIN ContractBHistory cb ON a.ID=cb.AppID
FULL OUTER JOIN MemberPolicy m1 ON ca.PolicyNumber=m1.PolicyNumber
FULL OUTER JOIN MemberPolicy m2 ON ca.PolicyNumber=m2.PolicyNumber
WHERE m1.PolicyNumber = 79301 OR m2.PolicyNumber = 79301;

Unfortunately, that means my WHERE clauses need to be more verbose:

... WHERE m1.PolicyNumber = 79301 OR m2.PolicyNumber = 79301;

instead of

... WHERE m.PolicyNumber = 79301;

Is it possible to achieve my ideal in this situation?  In the end, I desire to have the ability to use these all of these clean WHERE clauses on the properly constructed SQL query:

... WHERE a.MemberName = 'Annika Hansen';

... WHERE m.PolicyNumber = 79301;

... WHERE m.ID = 79;

... WHERE a.ID = 74656;

I am using SQL-Server, but I have tried to phrase this as a general question about SQL. Please let me know if I have been unclear - thank you in advance!

Here is an example with undesired results (thanks to @TheEsisia for most of this:)

declare @Applications table (ID int, MemberName varchar(30))
declare @ContractAHistory table (ID int, AppID int, PolicyNumber varchar(30))
declare @ContractBHistory table (ID int, AppID int, PolicyNumber varchar(30))
declare @MemberPolicy table (ID int, PolicyNumber varchar(30))

Insert Into @Applications Values
 (1, 'AA')
,(2, 'BB')
,(3, 'CC')
,(4, 'DD')

Insert Into @ContractAHistory Values
  (1, 1, 'A')
 ,(2, 2, 'B')

Insert Into @ContractBHistory Values
 (1, 3, 'H12007')
,(2, 4, 'GT31')

Insert Into @MemberPolicy Values
 (1, 'A')
,(2, 'B')
,(3, 'H12007')
,(4, 'GT31')

SELECT * FROM @Applications a
FULL OUTER JOIN @ContractAHistory ca ON a.ID=ca.AppID
FULL OUTER JOIN @ContractBHistory cb ON a.ID=cb.AppID
FULL OUTER JOIN @MemberPolicy m ON
(ca.PolicyNumber=m.PolicyNumber AND cb.PolicyNumber=m.PolicyNumber)
WHERE m.PolicyNumber = 'GT31';

Update: @TheEsisia helped me see that replacing the AND with an OR in the last query there achieves my desired results.  But answering @ThorstenKettner's questions: I certainly may not need all the FULL OUTER JOINs - however, I do want to pull up all information based on a specific WHERE clause. I can get requests for information with only one piece of the puzzle, so I'd like to pull up everything based on only an m.ID or an AppID or a PolicyNumber. For efficiency, I'm hoping to use the same primary query and only change the WHERE clause appropriately.  Also, each PolicyNumber matches to one Member and one Contract (either A or B) and one a.ID. That is where the complexity comes in: I never know from the PolicyNumber which kind of Contract it is. I hope that helps to clear up a bit about my use cases. Thanks to all.

Body:
Here is how we should access the tables:

With a policy number we find the policy record.

Linked to that record is either an A contract record or a B contract record. So we must outer join these tables.

Then we want the application for the contract found. This can be done with an inner join, because we always expect a match. (We don't want contracts without a matching application entry. Or, in case we do, switch this to a left outer join)

The complete query:

SELECT *
FROM @MemberPolicy m
LEFT OUTER JOIN @ContractAHistory ca ON ca.PolicyNumber = m.PolicyNumber
LEFT OUTER JOIN @ContractBHistory cb ON cb.PolicyNumber = m.PolicyNumber
INNER JOIN @Applications a ON a.ID IN (ca.AppID, cb.AppID)
WHERE m.PolicyNumber = 'GT31';

In case the contracts are very similar, you could also union the two tables. (But in that case it might be much better to change the database design and makes this one table only for the two contract types to start with.) In this situation we don't need any outer join; we select the policy, its contract and its application:

SELECT *
FROM @MemberPolicy m
INNER JOIN
(
  SELECT PolicyNumber, title, description, client, a_only_col, null as b_only_col
  FROM @ContractAHistory
  UNION ALL
  SELECT PolicyNumber, title, description, client, null as a_only_col, b_only_col
  FROM @ContractBHistory
) c ON c.PolicyNumber = m.PolicyNumber
INNER JOIN @Applications a ON a.ID = c.AppID
WHERE m.PolicyNumber = 'GT31';


答:
Of course not, and epsilon has little to do with it.  For example,

```<code>>>> x = 1e-200
>>> x
1e-200
</code>```

is far from epsilon, but

```<code>>>> x * x
0.0
</code>```

underflows to 0.  If we actually used epsilon instead, then, e.g., multiplying it by 0.25 would underflow to 0 too.

Provided your platform C compiler and hardware support the 754 standard, though, the sign of the zero would match the sign of the multiplicand:

```<code>>>> x * -x
-0.0
</code>```

Title: If you multiply the smallest positive floating point value by a non-zero number, are you guaranteed a non-zero result?

Body:
If I take epsilon to be the smallest positive non-zero floating point number (be it 16, 32, or 64 bit) and multiply epsilon by a non-zero floating point value of the same size:

Am I guaranteed a non-zero result of the same sign as the original
  value? Or do I risk rounding error (zero, or switching signs)?

Environment: Python/Numpy

Body:
Of course not, and epsilon has little to do with it.  For example,

>>> x = 1e-200
>>> x
1e-200

is far from epsilon, but

>>> x * x
0.0

underflows to 0.  If we actually used epsilon instead, then, e.g., multiplying it by 0.25 would underflow to 0 too.

Provided your platform C compiler and hardware support the 754 standard, though, the sign of the zero would match the sign of the multiplicand:

>>> x * -x
-0.0


问:
Is using COUNT(*) or SELECT * a good idea?
I've heard several times that you shouldn't perform COUNT(*) or SELECT * for performance reasons, but wasn't able to dig up some further information about it.

I can imagine that the database is then using all columns for the action, which can be an impressive performance loss, but I'm not sure about that. Does somebody have further information about the topic?

答:
In case of COUNT(*) it depends on database and its version. For example in modern versions of MS SQL it doesn't matter [source needed].

So the best approach in case of COUNT(*) is to measure it.

Using SELECT * is really bad idea. * means read all columns which can be heavy IO and network operation (especially for various type of CHAR columns). Moreover -- rather rarely you need all columns.


问:
how to align progress bar in webview Android?
I wrote simple web view application in android but the progress bar is showing the very top of the application click
here to view the image.
actually, I want to do like this click here

This is my
Main activity

```<code>public class MainActivity extends AppCompatActivity implements MyWebChromeClient.ProgressListener {

WebView wv;
private ProgressBar mProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wv=(WebView) findViewById(R.id.webview);
    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.getLoadsImagesAutomatically();
    settings.getBuiltInZoomControls();
    settings.setSaveFormData(true);
    settings.setEnableSmoothTransition(true);
    settings.setNeedInitialFocus(true);
    settings.setSavePassword(true);
    settings.setDomStorageEnabled(true);
    settings.setPluginState(WebSettings.PluginState.ON);
    // add progress bar
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    wv.loadUrl("https://www.w3schools.com/");
    wv.setWebChromeClient(new MyWebChromeClient(this));
    wv.setWebViewClient(new WebViewClient(){
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            mProgressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mProgressBar.setVisibility(View.GONE);

        }
    });
}

@Override
public void onBackPressed() {
    if(wv.canGoBack()){

        wv.goBack();
    }
    else{
        super.onBackPressed();
    }
}

@Override
public void onUpdateProgress(int progressValue) {
    mProgressBar.setProgress(progressValue);
    if (progressValue == 100) {
        mProgressBar.setVisibility(View.INVISIBLE);
    }
}}
</code>```

In this layout i added webview and progressbar.

activity_main.xml

```<code> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.johnson.apple.MainActivity">
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
    <ProgressBar
        android:id="@+id/progressBar"
        android:minHeight="2dip"
        android:maxHeight="2dip"
        android:progressDrawable="@drawable/bg_progress_bar_webview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar.Horizontal" />
</RelativeLayout>
</code>```

Hope anyone can help me
Thnaks in advance

答:
Add in your ProgressBar

```<code>android:layout_gravity="center_vertical|center_horizontal"
android:layout_centerInParent="true"
</code>```

so your ProgressBar should be

```<code><ProgressBar
android:id="@+id/progressBar"
android:minHeight="2dip"
android:maxHeight="2dip"
android:progressDrawable="@drawable/bg_progress_bar_webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_centerInParent="true"
style="@android:style/Widget.ProgressBar.Horizontal" />
</code>```

Body:
I wrote simple web view application in android but the progress bar is showing the very top of the application click
here to view the image.
actually, I want to do like this click here

This is my
Main activity

public class MainActivity extends AppCompatActivity implements MyWebChromeClient.ProgressListener {

WebView wv;
private ProgressBar mProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wv=(WebView) findViewById(R.id.webview);
    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.getLoadsImagesAutomatically();
    settings.getBuiltInZoomControls();
    settings.setSaveFormData(true);
    settings.setEnableSmoothTransition(true);
    settings.setNeedInitialFocus(true);
    settings.setSavePassword(true);
    settings.setDomStorageEnabled(true);
    settings.setPluginState(WebSettings.PluginState.ON);
    // add progress bar
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    wv.loadUrl("https://www.w3schools.com/");
    wv.setWebChromeClient(new MyWebChromeClient(this));
    wv.setWebViewClient(new WebViewClient(){
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            mProgressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mProgressBar.setVisibility(View.GONE);

        }
    });
}

@Override
public void onBackPressed() {
    if(wv.canGoBack()){

        wv.goBack();
    }
    else{
        super.onBackPressed();
    }
}

@Override
public void onUpdateProgress(int progressValue) {
    mProgressBar.setProgress(progressValue);
    if (progressValue == 100) {
        mProgressBar.setVisibility(View.INVISIBLE);
    }
}}

In this layout i added webview and progressbar.

activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.johnson.apple.MainActivity">
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
    <ProgressBar
        android:id="@+id/progressBar"
        android:minHeight="2dip"
        android:maxHeight="2dip"
        android:progressDrawable="@drawable/bg_progress_bar_webview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar.Horizontal" />
</RelativeLayout>

Hope anyone can help me
Thnaks in advance

Body:
Add in your ProgressBar

android:layout_gravity="center_vertical|center_horizontal"
android:layout_centerInParent="true"

so your ProgressBar should be

<ProgressBar
android:id="@+id/progressBar"
android:minHeight="2dip"
android:maxHeight="2dip"
android:progressDrawable="@drawable/bg_progress_bar_webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_centerInParent="true"
style="@android:style/Widget.ProgressBar.Horizontal" />


问:
How to search a string in multiple files and return the names of files in Powershell?
I have started learning powershell a couple of days ago, and I couldn't find anything on google that does what I need so please bear with my question.

I have been asked to replace some text strings into multiple files. I do not necessarily know the extension of the possible target files and I don't know their location either. So far I have managed to recursively browse into the directory (get-ChildItem -recurse) and find the string I was looking for with get-content and select-string:

```<code>Get-ChildItem -recurse | Get-Content | Select-String -pattern "dummy"
</code>```

The problem is, I can see the occurences of the text I am looking for, but I don't know how to tell PS to return the path and the name for every matching files as well.

How can I get the name and location of the files that contains the expression I am looking for?

答:
This is how I would do it, you don't need get-content:

```<code>ls -r | Select-String dummy | select line,path
</code>```

or

```<code>ls -r | Select-String dummy | fl *
</code>```

To see what the different properties are...

This is faster.  The second argument is -filter:

```<code>ls -r . *.bat | select-string netsh

ls -r -path . -filter *.bat | select-string netsh
</code>```

Body:
I have started learning powershell a couple of days ago, and I couldn't find anything on google that does what I need so please bear with my question.

I have been asked to replace some text strings into multiple files. I do not necessarily know the extension of the possible target files and I don't know their location either. So far I have managed to recursively browse into the directory (get-ChildItem -recurse) and find the string I was looking for with get-content and select-string:

Get-ChildItem -recurse | Get-Content | Select-String -pattern "dummy"

The problem is, I can see the occurences of the text I am looking for, but I don't know how to tell PS to return the path and the name for every matching files as well.

How can I get the name and location of the files that contains the expression I am looking for?

Body:
This is how I would do it, you don't need get-content:

ls -r | Select-String dummy | select line,path

or

ls -r | Select-String dummy | fl *

To see what the different properties are...

This is faster.  The second argument is -filter:

ls -r . *.bat | select-string netsh

ls -r -path . -filter *.bat | select-string netsh