我有一个SQL表(产品),如下面的格式
<table style="height: 44px; width: 340px;">
<tbody>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">id</td>
<td style="width: 217px; height: 18px;">colName</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">5</td>
<td style="width: 217px; height: 18px;">Backup Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">26</td>
<td style="width: 217px; height: 18px;">Backup Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">27</td>
<td style="width: 217px; height: 18px;">Backup Normal</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">28</td>
<td style="width: 217px; height: 18px;">Backup Plus Slim</td>
</tr>
<tr style="height: 17px;">
<td style="width: 109px; height: 17px;">29</td>
<td style="width: 217px; height: 17px;">wd Backup Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">30</td>
<td style="width: 217px; height: 18px;">Backup-Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">38</td>
<td style="width: 217px; height: 18px;">wd(Backup Plus Slim)</td>
</tr>
</tbody>
</table>
&#13;
在搜索 Backup Plus Slim ST2R122300 时,我想要完全匹配的行 在产品表中(即逐字逐句)。 我将如何在SQL查询中实现它。
答案 0 :(得分:1)
可以使用Full-Text Index
检查此Doc
或者使用LIKE
'%[^a-z]SearchValue[^a-z]%'
或LIKE '%SearchValue%'
SELECT * FROM PRODUCTS WHERE COLNAME LIKE '%[^a-z]SearchValue[^a-z]%';
为什么还需要数据库连接?我想你使用jQuery
$("#searchInput").keyup(function() {
//split the current value of searchInput
var data = this.value.split(" ");
//create a jquery object of the rows
var jo = $("#fbody").find("tr");
if (this.value == "") {
jo.show();
return;
}
//hide all the rows
jo.hide();
//Recusively filter the jquery object to get results.
jo.filter(function(i, v) {
var $t = $(this);
for (var d = 0; d < data.length; ++d) {
if ($t.is(":contains('" + data[d] + "')")) {
return true;
}
}
return false;
})
//show the rows that match.
.show();
}).focus(function() {
this.value = "";
$(this).css({
"color": "black"
});
$(this).unbind('focus');
}).css({
"color": "#C0C0C0"
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="searchInput" value="Type To Filter">
<br/>
<table style="height: 44px; width: 340px;">
<thead>
<tr>
<th>Id</th>
<th>ColName</th>
</tr>
</thead>
<tbody id="fbody">
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">5</td>
<td style="width: 217px; height: 18px;">Backup Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">26</td>
<td style="width: 217px; height: 18px;">Backup Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">27</td>
<td style="width: 217px; height: 18px;">Backup Normal</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">28</td>
<td style="width: 217px; height: 18px;">Backup Plus Slim</td>
</tr>
<tr style="height: 17px;">
<td style="width: 109px; height: 17px;">29</td>
<td style="width: 217px; height: 17px;">wd Backup Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">30</td>
<td style="width: 217px; height: 18px;">Backup-Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">38</td>
<td style="width: 217px; height: 18px;">wd(Backup Plus Slim)</td>
</tr>
</tbody>
</table>
答案 1 :(得分:0)
select * from products where colName='Backup Plus Slim ST2R122300';
&#39; *&#39; (不带引号) - 返回所有列。
产品 - 表格的名称。
colName - 列的名称。