Thread: Counting Row
<div class="Section1"><p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size: 12.0pt"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial">Hi postgre people. Can anybody help to fix performance of my query?</span></font><p class="MsoNormal"><fontface="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial">Let say, I have <b><span style="font-weight:bold">n</span></b> number of queue ticket. (Which I use SELECT).</span></font><pclass="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial">Is there faster method to know where is my ticket number in queue?</span></font><p class="MsoNormal"><fontface="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial">I use (while in PHP script ) and count one by one until my ticket number match with row field .</span></font><pclass="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial">$sql="select * from [MYTABLE] where [CONDITION] order by [FIELDORDER];</span></font><p class="MsoNormal"><fontface="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial">$rs=&$ctclink->Execute($sql);</span></font><p class="MsoNormal"><font face="Arial" size="2"><spanstyle="font-size:10.0pt; font-family:Arial">$ctr=1;</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial">$pos=0;</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> while (!$rs->EOF) {</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> if ($rs->fields[0]==$recid) {</span></font><p class="MsoNormal"><font face="Arial" size="2"><spanstyle="font-size:10.0pt; font-family:Arial"> $pos=$ctr;</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> break;</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> } else {</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> $ctr++;</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> $rs->MoveNext(); }</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> }</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> print $pos</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; font-family:Arial">is there any method to do that with simple??</span></font><p class="MsoNormal"><font face="Arial" size="2"><spanstyle="font-size:10.0pt; font-family:Arial"> </span></font><p class="MsoNormal"><b><font face="Broadway BT" size="3"><span style="font-size: 12.0pt;font-family:"Broadway BT";font-weight:bold">Thanks,</span></font></b><p class="MsoNormal"><font face="Times New Roman"size="3"><span style="font-size: 12.0pt"> </span></font></div>
I understand you need to count of tickets smaller than $recid given [CONDITION], in that case:
$sql="select count(*) from [MYTABLE] where [CONDITION] and ticketnumber <=" . $recid ;
$sql="select count(*) from [MYTABLE] where [CONDITION] and ticketnumber <=" . $recid ;
On 7/21/05, Ricky Sutanto <ricky@connexiasolutions.com> wrote:
Hi postgre people. Can anybody help to fix performance of my query?
Let say, I have n number of queue ticket. (Which I use SELECT).
Is there faster method to know where is my ticket number in queue?
I use (while in PHP script ) and count one by one until my ticket number match with row field .
$sql="select * from [MYTABLE] where [CONDITION] order by [FIELDORDER];
$rs=&$ctclink->Execute($sql);
$ctr=1;
$pos=0;
while (!$rs->EOF) {
if ($rs->fields[0]==$recid) {
$pos=$ctr;
break;
} else {
$ctr++;
$rs->MoveNext(); }
}
print $pos
is there any method to do that with simple??
Thanks,