NiTrino Posted June 29, 2007 Report Share Posted June 29, 2007 Kas ir saskāries tas zin, ka grupējot postgresā, grupēšanā jānorāda visi lauki, kas tiek selektēti: select u.id, u2.userid from users u join users_about u2 on u.id=u2.userid group by u.id; ERROR: column "u2.userid" must appear in the GROUP BY clause or be used in an aggregate function diemžēl tas izjauc rezultātus. Kāds zin kā izvairīties? Link to comment Share on other sites More sharing options...
andrisp Posted June 29, 2007 Report Share Posted June 29, 2007 Tāds interesants kverijs... Ko tu tieši tur gribi izselektēt ? Pastāsti - varbūt pavisam savādāk var. Link to comment Share on other sites More sharing options...
NiTrino Posted June 29, 2007 Author Report Share Posted June 29, 2007 HEEEELP, palīdziet man atrast REPLY pogu, citādi jāQUOTĒ bezjēgā. nē, runa nav par šito konkrēto... to es minēju kā piemēru. Tādā ziņā, ka šitas MySQL nostrādā, Postgresā - nē. Link to comment Share on other sites More sharing options...
bubu Posted June 29, 2007 Report Share Posted June 29, 2007 Kāda jēga selektēt u2.userid, ja tas ir vienāds ar u.id ? Raksti select u.id, u.id from users u join users_about u2 on u.id=u2.userid group by u.id; Es arī māku uzrakstī bezjēdzīgus kverijus, kuri uz vienas DBPVS strādās, bet uz citām nestrādās. Link to comment Share on other sites More sharing options...
NiTrino Posted June 29, 2007 Author Report Share Posted June 29, 2007 (edited) Nu nav runa par šito konkrētu kveriju... varēju uzrakstīt arī šitā: SELECT x.id,x.custid,y.catid FROM table1 x JOIN table2 y ON x.id=y.catid GROUP BY x.custid Edited June 29, 2007 by NiTrino Link to comment Share on other sites More sharing options...
andrisp Posted June 29, 2007 Report Share Posted June 29, 2007 (edited) postgresql subselektus atbalsta, vai ne ? Tad varētu kaut kā šādi moška: SELECT t1.z, (SELECT t2.y FROM table t2 WHERE t1.id = t2.id LIMIT 1 ) as y FROM table t1 GROUP BY t1.z Netestēju, nezinu vai iet. Edited June 29, 2007 by andrisp Link to comment Share on other sites More sharing options...
NiTrino Posted June 29, 2007 Author Report Share Posted June 29, 2007 (edited) ERROR: subquery uses ungrouped column "t1.id" from outer query SELECT t1.z, (SELECT t2.y FROM table t2 WHERE t1.id = t2.id LIMIT 1 ) as y FROM table t1 GROUP BY t1.z, [b]t1.id[/b] tā gan iet. Edited June 29, 2007 by NiTrino Link to comment Share on other sites More sharing options...
Recommended Posts