我该如何更改日期

时间:2016-08-24 17:26:48

标签: sql oracle oracle11g

我正在使用此查询

SELECT 
    A.EMP_NO, A.EMP_NAME, A.DEPARTMENT_NAME, A.ATT_DATE, 
    CASE 
       WHEN B.EMP_NO IS NULL 
          THEN 'A' 
          ELSE 'P' 
    END PRESENT_STATUS  
FROM 
    (SELECT 
         A.EMP_NO, A.EMP_NAME, A.DEPARTMENT_NAME, 
         B.ATT_DATE  
     FROM 
         EMPLOYEES A, 
         (SELECT 
              TO_DATE(:P_FROM_DATE) + LEVEL ATT_DATE  
          FROM DUAL  
          CONNECT BY LEVEL <= TO_DATE(:P_TO_DATE) - TO_DATE(:P_FROM_DATE)) B
    WHERE 
        TRIM(TO_CHAR(B.ATT_DATE, 'DAY')) <> 'SUNDAY') A,  
        (SELECT EMP_NO, EMP_NAME, DEPARTMENT_NAME, TRUNC(TIME_STAMP) ATT_DATE  
      FROM EMP22  
      GROUP BY EMP_NO, EMP_NAME, DEPARTMENT_NAME, TRUNC(TIME_STAMP)) B  
WHERE A.EMP_NO = B.EMP_NO(+) AND A.ATT_DATE = B.ATT_DATE(+)  
GROUP BY A.EMP_NO, A.EMP_NAME, A.DEPARTMENT_NAME, A.ATT_DATE, B.EMP_NO 

查询结果是这样的

| EMP_Name | emp_NO | Department_name | 2013-06-01 | 2013-06-02 | 2013-06-03 | 2013-06-04 | 2013-06-05 | 
|  Naren   |      1 |         22 |         A |        A |            A |           A |          P |           
|  Srinu   |      2 |         22 |         P |        P |            P |           P |          P |        
|  Blah    |      3 |         22 |         A |        P |            P |           P |          P | 

我需要像这样日期的结果应该是这样的

| EMP_Name | emp_NO | Department_name | 01 | 02 | 03 |04 | 05 | 
|  Naren |          1 |                        22 |                A |   A |   A |  A |   P |           
|  Srinu |            2 |                       22 |                P |   P |    P |  P |   P |        
|  Blah |             3 |                       22 |                 A |   P |   P |   P |   P |
你可以帮我修改我的查询吗

1 个答案:

答案 0 :(得分:1)

试试这个:

<?php
//store.php

// Create connection
$conn = new mysqli('localhost','root','','master');

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

//go query

$r = $_POST['cid'];
$e = $_POST['uid'];
$q = $_POST['ic'];
$j = $_POST['tid'];
$h = $_POST['ip'];
$i = $_POST['iq'];
$x = mysqli_query($conn,"insert into transactionb values('".$j."','".$r."','".$e."','".$q."','".$i."','".$h."')");
echo mysqli_error($conn);
if($x){echo 'success';
echo '<script>window.location = "../staffentryCID.php"</script>';}

$conn->close();
?>