状态中的Oracle 11g SQL故障单时间

时间:2017-02-06 22:02:02

标签: sql oracle

我想计算一张票在每个状态中花费的时间,但只有最初将票证置于状态时的日期时间戳。票证的下一个记录将是一个不同的状态,其中包含rowstamp和datetime>比第一个rowstamp和datetime以及相同的票号。两张票的样本如下:

<?php
 ob_start();
 session_start();
 if( isset($_SESSION['user'])!="" ){
  header("Location: home.php");
 }
 include_once 'db.php';

 $error = false;

 if ( isset($_POST['btn-signup']) ) {

  // clean user inputs to prevent sql injections
  $name = trim($_POST['name']);
  $name = strip_tags($name);
  $name = htmlspecialchars($name);

  $email = trim($_POST['email']);
  $email = strip_tags($email);
  $email = htmlspecialchars($email);

  $pass = trim($_POST['pass']);
  $pass = strip_tags($pass);
  $pass = htmlspecialchars($pass);

  $Nume = trim($_POST['Nume']);
  $Nume = strip_tags($Nume);
  $Nume = htmlspecialchars($Nume);

  $Prenume = trim($_POST['Prenume']);
  $Prenume = strip_tags($Prenume);
  $Prenume = htmlspecialchars($Prenume);

  $NumePrenume = trim($_POST['NumePrenume']);
  $NumePrenume = strip_tags($NumePrenume);
  $NumePrenume = htmlspecialchars($NumePrenume);

  $CNP = trim($_POST['CNP']);
  $CNP = strip_tags($CNP);
  $CNP = htmlspecialchars($CNP);

    $NumarTelefon = trim($_POST['NumarTelefon']);
  $NumarTelefon = strip_tags($NumarTelefon);
  $NumarTelefon = htmlspecialchars($NumarTelefon);

    $ContBancar = trim($_POST['ContBancar']);
  $ContBancar = strip_tags($ContBancar);
  $ContBancar = htmlspecialchars($ContBancar);

    $Poza = trim($_POST['Poza']);
  $Poza = strip_tags($Poza);
  $Poza = htmlspecialchars($Poza);

    $Locatie = trim($_POST['Locatie']);
  $Locatie = strip_tags($Locatie);
  $Locatie = htmlspecialchars($Locatie);

    $NumarPunctaj = trim($_POST['NumarPunctaj']);
  $NumarPunctaj = strip_tags($NumarPunctaj);
  $NumarPunctaj = htmlspecialchars($NumarPunctaj);

    $Referal = trim($_POST['Referal']);
  $Referal = strip_tags($Referal);
  $Referal = htmlspecialchars($Referal);

    $Varsta = trim($_POST['Varsta']);
  $Varsta = strip_tags($Varsta);
  $Varsta = htmlspecialchars($Varsta);

    $IP = trim($_POST['IP']);
  $IP = strip_tags($IP);
  $IP = htmlspecialchars($IP);

    $Cont = trim($_POST['Cont']);
  $Cont = strip_tags($Cont);
  $Cont = htmlspecialchars($Cont);


  // basic name validation
  if (empty($name)) {
   $error = true;
   $nameError = "Please enter your full name.";
  } else if (strlen($name) < 3) {
   $error = true;
   $nameError = "Name must have atleat 3 characters.";
  } else if (!preg_match("/^[a-zA-Z ]+$/",$name)) {
   $error = true;
   $nameError = "Name must contain alphabets and space.";
  }

  //basic email validation
  if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {
   $error = true;
   $emailError = "Please enter valid email address.";
  } else {
   // check email exist or not
   $query = "SELECT userEmail FROM users WHERE userEmail='$email'";
   $result = mysql_query($query);
   $count = mysql_num_rows($result);
   if($count!=0){
    $error = true;
    $emailError = "Provided Email is already in use.";
   }
  }


  // password validation
  if (empty($pass)){
   $error = true;
   $passError = "Please enter password.";
  } else if(strlen($pass) < 6) {
   $error = true;
   $passError = "Password must have atleast 6 characters.";
  }

  // password encrypt using SHA256();
  $password = hash('sha256', $pass);

  // if there's no error, continue to signup
  if( !$error ) {

   $query = "INSERT INTO users(userName,userEmail,userPass, Nume, Prenume, NumePrenume, CNP, NumarTelefon, ContBancar, Poza, Locatie, NumarPunctaj, Referal, IP, Cont) VALUES('$name','$email','$password','$Nume','$Prenume','$NumePrenume','$CNP','$NumarTelefon','$ContBancar','$Poza','$Locatie','$NumarPunctaj','$Referal','$IP','$Cont')";
   $res = mysql_query($query);

   if ($res) {
    $errTyp = "success";
    $errMSG = "Successfully registered, you may login now";
    unset($name);
    unset($email);
    unset($pass);
    unset($Nume);
    unset($Prenume);
    unset($NumePrenume);
    unset($CNP);
    unset($NumarTelefon);
    unset($ContBancar);
    unset($Poza);
    unset($Locatie);
    unset($NumarPunctaj);
    unset($Referal);
    unset($Varsta); 
    unset($IP);
    unset($Cont);   
   } else {
    $errTyp = "danger";
    $errMSG = "Something went wrong, try again later..."; 
   } 

  }


 }
?>

我不知道我在哪里使用过去的数据集,该数据集具有同一记录中每个状态的开始和结束时间。但不仅仅是开始时间。 谢谢你的帮助

1 个答案:

答案 0 :(得分:1)

只需使用lead()

select t.*,
       lead(changedate) over (partition by ticket order by changedate) as next_changedate
from tickets t;

我不确定你想要如何计算差异。您可以减去这两个值并获得天数差异。