我有持续时间表,它有两列sd_time(开始时间)和sd_etime(结束时间) 我想选择所有不开始和结束的时间(11:30 - 12:05) 所以如果sd_stime = 12:00和sd_etime = 1:00它将返回 但如果st_stime = 11:00且sd_eitme = 12:00则不会返回
SELECT *
FROM d_services_type_durations dsd
FROM d_services_type_durations dsd
WHERE (dsd.sd_stime <= '11:30' OR dsd.sd_stime >= '12:05')
AND
(dsd.sd_etime <= '11:30' OR dsd.sd_etime >= '12:05')
答案 0 :(得分:1)
试试这个:
SELECT *
FROM d_services_type_durations dsd
WHERE dsd.sd_stime < '11:30' OR dsd.sd_stime > '12:05'
OR
dsd.sd_etime < '11:30' OR dsd.sd_etime > '12:05'
答案 1 :(得分:0)
这是你的意思吗?
<?php
$sql="SELECT * FROM administrators";
$record=mysql_query($sql);
function drop($id,$email){
$q="DELETE FROM administrators WHERE id='$id' AND email='$email'";
mysql_query($q);
header("Refresh:0");
}
if (isset($_GET['drop'])) {
$id=$_GET['id'];$email=$_GET['email'];
drop($id,$email);
}
?>
<title>Admins Table</title>
<style>
table, th, td {
border: 2px solid black;
border-collapse: collapse;
}
#creating {
font:bold;
font-size:1.6em;
}
</style>
<a href='cadmin.php' id='creating'>Create New Admin</a><br/><br/>
<table width="920" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Gender</th>
<th>Email</th>
<th>Address</th>
<th>Update</th>
<th>Delete</th>
</tr>
<?php
while($row=mysql_fetch_assoc($record)){
echo'<tr>';
echo'<td>'.$row['id'].'</td>';
echo'<td>'.$row['first_name'].'</td>';
echo'<td>'.$row['last_name'].'</td>';
echo'<td>'.$row['phone'].'</td>';
echo'<td>'.$row['gender'].'</td>';
echo'<td>'.$row['email'].'</td>';
echo'<td>'.$row['address'].'</td>';
echo'<td>'."<a href='' onclick=''>Edit</a>".'</td>';
echo'<td>'."<a href='? drop=ss&id=".$row['id'].'&email='.$row['email']."'> Drop</a>".'</td>';
echo'</tr>';
}
?>
答案 2 :(得分:0)
尝试使用STR_TO_DATE函数
SELECT * FROM d_services_type_durations dsd WHERE
dsd.sd_stime <> '11:30'
AND
STR_TO_DATE(dsd.sd_stime, "%k:%i") <= STR_TO_DATE('12:05', "%k:%i")
AND
STR_TO_DATE(dsd.sd_etime, "%k:%i") <= STR_TO_DATE('11:30', "%k:%i")
AND
STR_TO_DATE(dsd.sd_etime, "%k:%i") <= STR_TO_DATE('12:05', "%k:%i")
主要问题是您使用的类型varchar不能很好地处理这种比较。我建议您更改模式中的类型
,而不是使用此解决方案,将所有内容转换为日期时间