Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4126012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:56:42+00:00 2026-05-20T23:56:42+00:00

How can I group a query result by a field that is not saved

  • 0

How can I group a query result by a field that is not saved in the database.

For example I want to group the result by duration which is came from subtraction of start time and end time.

here is how i find out the duration

date1= $row_TicketRS['CloseDate']; 
$date2 = $row_TicketRS['OpenDate'];

$diff = abs(strtotime($date2) - strtotime($date1)); 

$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));


if ( $days > 0)

{

$time1 = $row_TicketRS['OpenTime'];
$time2= $row_TicketRS['CloseTime'];

$t1=($time1); 
$t2=($time2);

$end=('14:30');
$start=('07:30');

$n = $end- $t1;

$n2 = $t2- $start;

$Hours2 = floor(($n+$n2)+(($days-1)*7));

echo   $Hours2.' Hours'; 

but know i do not know how to add it to the query

here is my query

$strQuery = "SELECT count(`ticket`.TicketID) as TotOutput, department.`DeptName` FROM `ticket`, `user`, department where ticket.OwnerID = user.EmpNo and  user.`DepartmentID` = department.`DepartmentID` and OpenDate between'".$DateFrom."' And '".$DateTo."'"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:56:43+00:00Added an answer on May 20, 2026 at 11:56 pm

    How about adding that computed value to the query with an alias like this:

    SELECT some_fields, end - start AS duration FROM table ORDER BY duration
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python regular expression that contains a group which can occur zero
Can this be done w/ linqtosql? SELECT City, SUM(DATEDIFF(minute,StartDate,Completed)) AS Downtime FROM Incidents GROUP
i'm trying to get optimize an very old query that i can't wrap my
What I need is query that show : How many times value in field
I want to use LINQ to group data from a DataTable (columns: userid, chargetag,
I'm getting an unexpected result for my query in group function. I'm using the
Possible Duplicate: Group files in Visual Studio The problem is, that I want to
If all tables I want to delete from have the column gamer_id can i
I have a search field, and using that single text box I want the
I've got the following query: SELECT name, GROUP_CONCAT(job SEPARATOR ','), count(*) FROM users GROUP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.