1. Welcome! Please take a few seconds to create your free account to post threads, make some friends, remove a few ads while surfing and much more. ClutchFans has been bringing fans together to talk Houston Sports since 1996. Join us!

SQL help again ...

Discussion in 'BBS Hangout' started by Luckyazn, Jun 12, 2012.

Tags:
  1. Luckyazn

    Luckyazn Member

    Joined:
    Jun 23, 2003
    Messages:
    4,375
    Likes Received:
    68
    If I need to write a queary to count the number of "reprintx" with a time trend (This is a calucation of the difference between Process Time vs Reprint Time, where time is greater than 5 mins count the record)

    I need to show the number of time "reprintx" are done after 5 mins of the original.

    Do I need to incorp. the Datediff statement?

    I found the two columns "process time" and "reprintx time"

    Any help to jump start will help.

    Thanks,
     
    #1 Luckyazn, Jun 12, 2012
    Last edited: Jun 13, 2012
  2. DrLudicrous

    DrLudicrous Member

    Joined:
    May 9, 2002
    Messages:
    3,936
    Likes Received:
    203
    It looks like TIMESTAMPDIFF may be your best bet. DateDiff on returns the number of days, not minutes, with TimestampDiff you can specify the unit.

    Select *
    From table
    Where TIMESTAMPDIFF(MINUTE, processTime, reprintTime) > 5
     
  3. EssTooKayTD

    EssTooKayTD Member

    Joined:
    Dec 15, 2005
    Messages:
    3,343
    Likes Received:
    74
    Is there a new row created with each reprint, or is the reprint column updated each time a reprint is done?
     
  4. Luckyazn

    Luckyazn Member

    Joined:
    Jun 23, 2003
    Messages:
    4,375
    Likes Received:
    68
    Yes, there's a new row for each reprint during the month.

    A month could have 20+


    ** one more thing .... I can extract the month and year in a datetime with no problem

    "select extract (year from attempt_date)AS Years"
    but I can't extract just the TIME from the datetime ....

    dont I need to minus the two diff? reprint time and process time but the mm/dd/yy is in the time line too long with the time

    "05/12/2012 11:13:56" Process Time
    "05/12/2012 15:11:34" Reprint Time

    Don't I need to somehow calculate the different between the two to get "over 5mins"
     
    #4 Luckyazn, Jun 12, 2012
    Last edited: Jun 13, 2012
  5. DrLudicrous

    DrLudicrous Member

    Joined:
    May 9, 2002
    Messages:
    3,936
    Likes Received:
    203
    If the data is on separate rows then you'll need to join the table to itself to compare the dates, I'm assuming there is some sort of ID that allows you to tell that two records are related along with a unique id for each row.

    It would help if you could list the columns you have that are used in the process.
     
  6. EssTooKayTD

    EssTooKayTD Member

    Joined:
    Dec 15, 2005
    Messages:
    3,343
    Likes Received:
    74
    To me it sounds like you need to first filter your query to just show the rows of the printout you are looking at, like Dr. Luda said. Some PrintID or something that represents the same print job/document.

    ASSUMPTION: All the "Process Time" values should be the same representing when the first/original printing happened right?

    So just sort your query by reprint time. Filter out any times that are less than ProcessTime + 5 mins. The row count is how many reprints you had 5 minutes past your original print time.

    You shouldn't need to parse your date at all, if you are just looking for the number of reprints.
     
  7. Yung-T

    Yung-T Member

    Joined:
    Apr 16, 2009
    Messages:
    24,403
    Likes Received:
    7,053
    "Luckyazn - My life with SQL"

    A heart-warming tale about a man and his daily confrontations with SQL, narrated by Morgan Freeman. Giving a great look into the stereotypes about Asians, computers and their struggles this book will hook you with it's original style, anecdotes and a great portion of humor. Written by the author of the NY Times bestseller "Being Asian on ClutchFans - a shocking story about ignorance and racism in our society".

    Oprah Winfrey: "This book will change the way how people think about Asians in our society. We assume they are masters in everything related to computers and math but these are blatant stereotypes that hurt Asians the most and put them under great pressure to perform up to the standards that we lay on them."

    "Luckyazn - My life with SQL" In stores Fall, 2012.
     
  8. EssTooKayTD

    EssTooKayTD Member

    Joined:
    Dec 15, 2005
    Messages:
    3,343
    Likes Received:
    74
    Apparently he's gotten through life using luck. We do like to gamble. I'm just joking Luckyazn. We do like to gamble though.
     
  9. pirc1

    pirc1 Member

    Joined:
    Dec 9, 2002
    Messages:
    14,137
    Likes Received:
    1,882
    What was this all about?
     
  10. tinman

    tinman 999999999
    Supporting Member

    Joined:
    May 9, 1999
    Messages:
    104,298
    Likes Received:
    47,185
    delete *
    from Clutchfans
    where TOFs=Y
     
  11. snc

    snc Member

    Joined:
    Oct 15, 2007
    Messages:
    995
    Likes Received:
    75
    DELETE * from Clutchfans WHERE registered_year = 1999

    :cool:
     
  12. tinman

    tinman 999999999
    Supporting Member

    Joined:
    May 9, 1999
    Messages:
    104,298
    Likes Received:
    47,185
    then you would delete the admin clutch and destroy the server!
     
  13. TreeRollins

    TreeRollins Member

    Joined:
    Nov 7, 2006
    Messages:
    2,052
    Likes Received:
    102
    DELETE * from Clutchfans WHERE registered_year = 1999 and member_name <> Clutch
     
  14. tinman

    tinman 999999999
    Supporting Member

    Joined:
    May 9, 1999
    Messages:
    104,298
    Likes Received:
    47,185
    Delete *
    from Clutchfans
    where favorite player playoff series victories=NULL
     
  15. snc

    snc Member

    Joined:
    Oct 15, 2007
    Messages:
    995
    Likes Received:
    75
    My fave player is Brian Cook so I'm ok.
     
  16. Luckyazn

    Luckyazn Member

    Joined:
    Jun 23, 2003
    Messages:
    4,375
    Likes Received:
    68
    Ok finally got it to work.

    I added the statement:

    Count (reprintx_ticket) as Reprintx

    Where AND ((reprintx_ticket - process_ticket) * 1440) > 4.3


    Now I get the number of "Reprintx" in a time frame by each employees

    but now I might need help on this one:

    Number of times the employee void a ticket that was already voided on a given day?
     
    #16 Luckyazn, Jun 13, 2012
    Last edited: Jun 13, 2012
  17. Prince

    Prince Member

    Joined:
    Apr 27, 2009
    Messages:
    5,375
    Likes Received:
    161
    [​IMG]
     
  18. Luckyazn

    Luckyazn Member

    Joined:
    Jun 23, 2003
    Messages:
    4,375
    Likes Received:
    68
    Would it be Void_Ticket - 1 ? Since the first one would be the first reprint? If I'm trying to get the total
     

Share This Page

  • About ClutchFans

    Since 1996, ClutchFans has been loud and proud covering the Houston Rockets, helping set an industry standard for team fan sites. The forums have been a home for Houston sports fans as well as basketball fanatics around the globe.

  • Support ClutchFans!

    If you find that ClutchFans is a valuable resource for you, please consider becoming a Supporting Member. Supporting Members can upload photos and attachments directly to their posts, customize their user title and more. Gold Supporters see zero ads!


    Upgrade Now