我正在使用MSSQL 2008:
SELECT c.ID as IDCliente, c.Nombre as name, c.Email as Email, p.ID as Pid,
p.nombre as pname, p.model as p.mod
FROM Clientes c
JOIN vArtistasClienteRandom vA ON (vA.IDCliente = c.ID)
JOIN RelProductoArtistas rpa ON (rpa.IDArtista = vA.IDArtista)
JOIN Productos p ON (rpa.IDProducto = p.ID)
WHERE IDCliente = 22343
**我有这个结果:
idcliente I clinombre I email I pid I pname I pmod**
22343 I Joan I xxx@yahoo.com I 22196 I adidas I blue
22343 I Joan I xxx@yahoo.com I 22725 I nike I blue
22343 I Joan I xxx@yahoo.com I 21794 I nike I green
我希望查询只返回一行,如下所示:
idcliente I name I email I pid1 I pid2 I pid3 I pname1 I pname2 I pname3 I pmod1 pmod2 I pmod3**
22343 I Joan I xxx@yahoo.com I 22196 I 22725 I 21794 I adidas I nike I nike I blue I blue I green