Home >Backend Development >PHP Tutorial > 数据库查询有关问题

数据库查询有关问题

WBOY
WBOYOriginal
2016-06-13 13:38:33912browse

数据库查询问题.在线等
数据表checkwork
userid startdate enddate remark
1 2011-11-01 2011-11-03 请假
1 2011-11-25 2011-11-26 因公外出
2 2011-11-04 2011-11-06 节假日

我现在需要查出11月份,userid为1的人的,“请假”的天数并显示出来,怎么实现啊??sql语句怎么写??...

------解决方案--------------------
SELECT COUNT(`remark`) AS 'Total' FROM `checkwork` WHERE `Userid`=1 GROUP BY `remark`;
------解决方案--------------------
再给一个比较直观(把sql那段注销掉)的,希望能帮到你,这个应该算伪代码

PHP code

<?php $startime="2011-11-11";//指定开始日期
$endtime="2011-12-02";//指定结束日期
Checkwork($startime,$endtime);
function Checkwork($startime,$endtime){
while($startime<=$endtime){
/*
 * 按上面的sql语句提取出$reamk的值
 * $sql="select * from checkwork where userid='1' and startdate<='$startime' and enddate>='$startime'";
 * $rs = $conn->Execute($sql);
 * $remak=$rs->Fields['remak']->Value;
 */    
echo $startime."-------备注".$remak."<br>";//读出日期与备注字段
    $startime=date('Y-m-d',strtotime($startime)+86400);
    }
}
?> <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn