嗨,我有一张桌子,我想查询,但有点生疏,可以帮忙。
首先,表结构:
SELECT
clientsites.ClientSitePk,
clientsites.ClientFk,
clientsites.SiteName,
clientsites.SiteType,
clientsites.FileNamePrefix,
clientsites.TempPostCode,
clientsites.TempPAF,
clientsites.ActualPAF,
concat_ws('\n', IF(LENGTH(pafaddresses.Line1),pafaddresses.Line1,NULL), IF(LENGTH(pafaddresses.Line2),pafaddresses.Line2,NULL), IF(LENGTH(pafaddresses.Line3),pafaddresses.Line3,NULL), IF(LENGTH(pafaddresses.Line4),pafaddresses.Line4,NULL), IF(LENGTH(pafaddresses.Line5),pafaddresses.Line5,NULL), IF(LENGTH(pafaddresses.PostTown),pafaddresses.PostTown,NULL), IF(LENGTH(pafaddresses.County),
pafaddresses.County,NULL), IF(LENGTH(pafaddresses.PostCode),pafaddresses.PostCode,NULL), IF(LENGTH(pafaddresses.CountryName),pafaddresses.CountryName,NULL)) AS AddressLabel,
pafaddresses.PostCode AS `Map`,
clientsites.Country,
clientsites.AddressLine1,
clientsites.AddressLine2,
clientsites.AddressLine3,
clientsites.AddressLine4,
clientsites.AddressLine5,
clientsites.PostTown,
clientsites.County,
clientsites.PostCode
FROM clientsites
INNER JOIN pafaddresses ON clientsites.ActualPAF = pafaddresses.id
我要做的是创建一个查询,为clientsites.ClientSitePk
的每条记录返回所有pafaddresses.PostCode
和clientsites.Country=1
,但我正在努力。
这是我到目前为止所做的:
//get client addresses in UK only
$rstmp = CustomQuery("SELECT * FROM clientsites where Country=1");
$datatmp = db_fetch_array($rstmp);
foreach ($datatmp as $row)
{
echo $row["ClientSitePk"];
}
不幸的是,它没有返回任何结果,实际上该表中有大约200行符合此条件的数据,有人可以告诉我如何
a)更正此查询并
b)包括连接表以获取pafaddresses.PostCode
值。