我问这没有代码,因为我想知道很多不返回行的方法吗?我现在使用的不是那么整洁。我现在使用的是“ 1 = 2”,它始终不返回任何行。
因此,我要问的是一种关于如何在sql语句中不返回行的好方法。
更新:
$sql = 'SELECT `a`.`id`,
`a`.`action_id`,
DATE_FORMAT(FROM_UNIXTIME(a.`time`), "%d-%m-%Y") as `date`,
DATE_FORMAT(FROM_UNIXTIME(a.`time`), "%H:%i") as `time`,
`a`.`amount_other_callers`,
`a`.`additional_data_incident`,
`a`.`additional_data_result`,
`a`.`additional_data_messagequality_start`,
`a`.`additional_data_messagequality_end`,
`a`.`additional_data_smsquality_start`,
`g`.`name` AS gemeente
FROM `actions` a
INNER JOIN actions_geo_communities AS ac
ON ac.lnk_action_id = a.id
INNER JOIN geodata_communities g
ON ac.lnk_community_id = g.id ';
if(Auth::user()->unit_id > 0) {
$sql.= ' INNER JOIN actions_geo_units AS au
ON au.lnk_action_id = a.id ';
}
if(Session::get('tk') === "1" && Session::get('ntk') === "1")
{
$sql.= ' WHERE `a`.`aangevuld` = 0 AND `a`.time > 1388530800';
}
else if (Session::get('tk') == 1)
{
$sql.= ' WHERE `a`.`aangevuld` = 0 AND `a`.`tk` = 1 AND `a`.time > 1388530800';
}
else if (Session::get('ntk') == 1)
{
$sql.= ' WHERE `a`.`aangevuld` = 0 AND `a`.`tk` = 0 AND `a`.time > 1388530800';
}
else
{
$sql.= ' WHERE 1=2';
}
if(Auth::user()->unit_id > 0) {
$sql.= ' AND `au`.`lnk_unit_id` = ' . Auth::user()->unit_id . ' ';
}
if(!empty($not_arr)) {
$sql.= ' AND `a`.`id` NOT IN (' . implode(',', $not_arr) . ') ';
}
最佳答案
最好的答案是不运行查询,您不需要任何数据,所以为什么要强调数据库
在您的情况下,请先检查是否选中两个或一个复选框,然后运行查询,否则根本不运行它
关于mysql - 如何不返回行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23514475/