这是基本的,但我不知道。我有两个表(SeriesTable和OtherTable)。SeriesTable具有给定系列的所有信息,包括其ID(名为“ seriesID”的列)。另外,OtherTable有一个名为“ seriescolumn”的列,该列也具有给定序列的ID。
我需要进行查询,以计算OtherTable的“ seriescolumn”中与SeriesTable中的seriesid列匹配的每个条目。因此,例如,如果SeriesTable中的seriesid为5,我需要计算OtherTable中有多少条目在series列中的值为5。
下面是我当前的代码,该代码只是从第一个表中获取信息,但是我不知道如何正确地从OtherTable中计算匹配的条目。
<?
$rs= mysql_query("SELECT seriesid FROM SeriesTable ORDER BY seriesid DESC");
while ($row= mysql_fetch_array($rs)) { ?>
content
<? } ?>
听起来您将需要联接和按语句分组。
SELECT s.seriesid, Count(*) As NumberOfSeries
FROM SeriesTable s Join
OtherTable o On s.seriesid = o.seriescolumn
Group By s.seriesid
ORDER BY seriesid DESC
这应该返回每个序列号和重复次数的计数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句