companyid boxid tableid time
1 1 1 11.55
1 2 1 11.58
1 1 1 12.00
1 1 1 12.05
2 1 1 8.00
2 1 1 8.05
2 2 3 9.05
2 2 3 9.10
3 1 5 13.00
3 1 5 13.05
sql query....
output
1 1 1 11.55
2 1 1 8.00
3 1 5 13.00
how i can i use distinct on company id basis here as on each row time is different
i want query where row should be selected on distinct company id basis and min time for that id
what query i should use
Loading
Jignesh TrivediPosted Jan 23, 2012, 5:58 AM
from the out put, ithink u required time on basis of company id , box id and table id.
if yes than try following query.
select companyid as companyid,boxid as boxid,tableid as tableid,min(time) as time
from YourTableName
group by companyid,boxid,tableid
hope this help.
Pravin MorePosted Jan 23, 2012, 4:07 AM
below query will work perfect for your requirment...
select max(companyid) as companyid,max(boxid) as boxid,max(tableid) as tableid,min(time) as time
from YourTableName
group by companyid
try it.
Thanks,
Pravin.