FROM PPL_PRODUCT_TESTID2
WHERE ((MONO = '5750333') AND (ITNO = '132961') AND (SYSTEMTYPE = '0036') AND (TESTFLAG = '1'))
Order by TIMESTAMP ASC
==> above gives me a TOTAL of 150
SELECT DISTINCT MAINSERNO, to_char(TIMESTAMP, 'MM/DD/YYYY HH24:MI:SS') as TIMESTAMP
FROM PPL_PRODUCT_TESTID2
WHERE ((MONO = '5750333') AND (ITNO = '132961') AND (SYSTEMTYPE = '0036') AND (TESTFLAG = '1'))
Order by TIMESTAMP ASC
==> above gives me a TOTAL of 165, of which 15 are MAINSERNO are duplicates. I have used the DISTINCT, why does it still produces duplicates?
Also, based on its TIMESTAMP, I would want to extract the count, and put them into its appropriate hourly time slot as shown in the printscreen, is that possible?
That is e.g from TIMESTAMP data of HH:MM:SS, those data that are after 00:30:00 and before 01:30:00 would be counted and place into the 01:30 Hours(18) timeslot.

How do I loop through the 24-hour time slot, instead of repeating each one as below:
also possible not to include the date, and only the time in the comparison condition?



Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 12:16 AM EDT
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 5, 2013, 8:31 PM EDT
The difference between two query with distinct that, first one will remove the duplicate of MAINSERNO column value, where in second query it will do the same, but it will different TIMESTAMP value for same MAINSERNO value. Therefore you are getting more count. To get that kind of output, first create a table and insert all this time
CREATE TABLE TimeCal
(
StartTime varchar(5),
EndTime varchar(5)
)
insert the record in this table like this
INSERT INTO TimeCal values('07:30','08:30')
INSERT INTO TimeCal values('08:30','08:30')
INSERT INTO TimeCal values('09:30','10:30')
...........................................................
...........................................................
...........................................................
INSERT INTO TimeCal values('05:30','06:30')
INSERT INTO TimeCal values('06:30','07:30')
Then write your query like this
Regards,
Iftikar
TAN WhoAMIRank #5,790 · 286 reputationPosted Aug 5, 2013, 9:06 PM EDT
how to I loop through the query to extract the count for the 24-hourly intervals?
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 5, 2013, 9:09 PM EDT
let we complete this first, then will look into second one.
Regards,
Iftikar
TAN WhoAMIRank #5,790 · 286 reputationPosted Aug 5, 2013, 9:22 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 5, 2013, 9:40 PM EDT
//you need write all other select query till 6:30
Regards,
Iftikar
TAN WhoAMIRank #5,790 · 286 reputationPosted Aug 5, 2013, 9:58 PM EDT
Could I have above in my C# code to extract out the count?
TAN WhoAMIRank #5,790 · 286 reputationPosted Aug 5, 2013, 10:09 PM EDT
would you like to join.me?
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 5, 2013, 10:22 PM EDT
Regards,
Iftikar
TAN WhoAMIRank #5,790 · 286 reputationPosted Aug 5, 2013, 10:25 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 5, 2013, 10:40 PM EDT
I will be not able join now
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 5, 2013, 10:48 PM EDT
public class TimeCal
{
public string StartTime {get;set;}
public string EndTime {get;set;}
public int TotalRecord {get;set;}
}
create a collection of this class
List
TimeCal timeCal=new TimeCal() { StartTime="07:30", EndTime="08:30"};
timeCals.Add(timeCal)
like that add for all time
then after getting the result by using the query, loop thru this collection
List
foreach(var timeCal in timeCals)
{
int count = (from p in dbcontext.Products
timeCal.TotalRecord=count;
timeCalsResult.Add(timeCal);
}
Regards,
Iftikar
TAN WhoAMIRank #5,790 · 286 reputationPosted Aug 5, 2013, 10:59 PM EDT
but how do I input in the timestamp condition to do the comparison?
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 5, 2013, 11:03 PM EDT
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 6, 2013, 12:48 AM EDT
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 6, 2013, 4:39 AM EDT
p.tt.Hour>timeCal.StartTime.Hour && p.tt.Hour
Regards,
Iftikar
TAN WhoAMIRank #5,790 · 286 reputationPosted Aug 11, 2013, 6:47 PM EDT
I realize that my code works only for today's date. If I want to retrieve the records of those past dates, I need to manually change the dates to those past dates, which is troublesome.
How can we modify the query such that it does the comparison of its TIMESTAMP based on the dates from the records retrieved from the table in the database?
Presently, this attached code compared with TIMESTAMP with today's date and its hourly interval.
thanks.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 11, 2013, 7:45 PM EDT
DateTime date= Convert.ToDateTime("02/02/2013");
DateTime next = date.AddHours(7.5);
Regards,
Iftikar
TAN WhoAMIRank #5,790 · 286 reputationPosted Aug 12, 2013, 12:08 AM EDT
above I am able to retrieve the date and time of the minimum...
how do I set today's time to be 12:00:00AM ?
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 12:16 AM EDT
Regards,
Iftikar
TAN WhoAMIRank #5,790 · 286 reputationPosted Aug 12, 2013, 12:34 AM EDT
how do I set my StartTime and EndTime to be dated from the database? that is to MO_Date. It always set to today's date, which I do not want.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 12, 2013, 1:34 AM EDT
Regards,
Iftikar
TAN WhoAMIRank #5,790 · 286 reputationPosted Aug 12, 2013, 4:41 AM EDT
I rephrase again...
at each StartTime and EndTime of the hourly interval, I would like it be to dated as the MO_DATE (as below), instead of the system's clock date. Presently, it follows the system's clock date which is not what I want.
var MO_Date = (from p in context.PPL_PRODUCT_TESTID2
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts