Php 进行一个只显示没有空值的行的查询
我试图创建一个查询语句,该语句将只获取在其列中不包含空值的行。但我不知道该怎么做 以下是查询语句:Php 进行一个只显示没有空值的行的查询,php,mysql,sql,database,Php,Mysql,Sql,Database,我试图创建一个查询语句,该语句将只获取在其列中不包含空值的行。但我不知道该怎么做 以下是查询语句: $query = "SELECT scrap_wafers.lot, scrap_wafers.wafer_cell, scrap_wafers.flow, ". "scrap_wafers.route, scrap_wafers.scrap_date, scrap_wafers.scrap_comment, ". "scrap_type_names.scrap_tag_name, scr
$query = "SELECT scrap_wafers.lot, scrap_wafers.wafer_cell, scrap_wafers.flow, ".
"scrap_wafers.route, scrap_wafers.scrap_date, scrap_wafers.scrap_comment, ".
"scrap_type_names.scrap_tag_name, scrap_wafers.engineer, scrap_wafers.disposition_date, ".
"scrap_wafers.disposition_comment, scrap_wafers.location, scrap_wafers.serial_sw, scrap_wafers.operator ".
"FROM scrap_wafers ".
"LEFT JOIN scrap_type_names ON scrap_type_names.serial_stn = scrap_wafers.serial_stn ".
"$cstring ".
"GROUP BY scrap_wafers.serial_sw ".
"ORDER BY scrap_wafers.scrap_date DESC ".
"LIMIT $numrecs";
$标准包括:
$criteria = array();
if (!empty($lot)) {
$lotarray = explode(',', $lot);
$lot_criteria_str = "(";
foreach ($lotarray as $lottmp) {
$lot_criteria_str = $lot_criteria_str . "scrap_wafers.lot like '%$lottmp%' OR ";
}
$lot_criteria_str = substr($lot_criteria_str,0,-3);
$lot_criteria_str = $lot_criteria_str . ")";
$criteria[] = $lot_criteria_str;
}
if (!empty($wafer_cell)) {
$waferarray = explode(',', $wafer_cell);
$wafer_criteria_str = "(";
foreach ($waferarray as $wafertmp) {
$wafer_criteria_str = $wafer_criteria_str . "scrap_wafers.wafer_cell like '%$wafertmp%' OR ";
}
$wafer_criteria_str = substr($wafer_criteria_str,0,-3);
$wafer_criteria_str = $wafer_criteria_str . ")";
$criteria[] = $wafer_criteria_str;
}
if (!empty($serial_flow)) $criteria[] = "scrap_wafers.serial_flow = '$serial_flow'";
if (!empty($serial_route)) $criteria[] = "scrap_wafers.serial_route = '$serial_route'";
if (!empty($operator)) $criteria[] = "scrap_wafers.operator = '$operator'";
if (!empty($serial_stn)) $criteria[] = "scrap_wafers.serial_stn = '$scrap_tag_name'";
if (!empty($scrap_date)) $criteria[] = "scrap_wafers.scrap_date = '$scrap_date'";
if (!empty($serial_step)) $criteria[] = "scrap_wafers.serial_step = '$serial_step'";
if (!empty($location)) $criteria[] = "scrap_wafers.location = '$location'";
if (!empty($completeness)) {
if ($completeness == 'Default') {
// Do nothing
}
else if ($completeness == 'Incomplete') {
$criteria[] = "scrap_wafers.disposition_date = null AND scrap_wafers.engineer = null AND ".
"scrap_wafers.disposition_comment = null AND scrap_wafers.location = null AND ".
"scrap_wafers.serial_stn = null";
}
else if ($completeness == 'Complete') {
$criteria[] = "scrap_wafers.disposition_date = not null AND scrap_wafers.engineer = not null AND ".
"scrap_wafers.disposition_comment = not null AND scrap_wafers.location = not null AND ".
"scrap_wafers.serial_stn = not null";
}
}
$cstring = "";
if (count($criteria) > 0) {
$cstring = "WHERE ".join(" AND ", $criteria);
} else {
$cstring = "WHERE 1=1 ";
}
$completure是我试图筛选空值完整或无空值完整的地方。您需要使用,not=null
Use IS NULL而不是=NULL NULL NULL/not NULL的测试为NULL/not NULL。你不能在这些测试中使用等号。是的,明白了。非常感谢。别担心。如果这个答案解决了你的问题,请随意接受。但是,应该指出的是,这个问题已经在stackoverflow上被回答了100次,所以下次搜索更多;答案被接受。感谢您的提醒,下次我会确保下次搜索更多:
...
else if ($completeness == 'Incomplete') {
$criteria[] = "scrap_wafers.disposition_date IS NULL AND scrap_wafers.engineer IS NULL AND ".
"scrap_wafers.disposition_comment IS NULL AND scrap_wafers.location IS NULL AND ".
"scrap_wafers.serial_stn IS NULL";
}
else if ($completeness == 'Complete') {
$criteria[] = "scrap_wafers.disposition_date IS NOT NULL AND scrap_wafers.engineer IS NOT NULL AND ".
"scrap_wafers.disposition_comment IS NOT NULL AND scrap_wafers.location IS NOT NULL AND ".
"scrap_wafers.serial_stn IS NOT NULL";
}
...