goma smile Posted January 5, 2009 Report Share Posted January 5, 2009 Labdien, Stāstīšu kā ir. Es taisu forumu un es gribu zināt, ka uzināt mysql veidā cik jaunu topic ir katrā sadaļā. Link to comment Share on other sites More sharing options...
bubu Posted January 5, 2009 Report Share Posted January 5, 2009 SELECT sadaļas.nosaukums, COUNT(*) FROM sadaļas JOIN forumi ON sadaļas.id = forumi.sadaļas_id GROUP BY sadaļas.nosaukums Link to comment Share on other sites More sharing options...
goma smile Posted January 5, 2009 Author Report Share Posted January 5, 2009 (edited) ir tnq a varbūt tu nezini kā saskaitīt atbildes man sanāca šitā bet ja piemēram sadaļā nav iekšā neviena raksta tad tas pazūd :( SELECT count(jautaajuma_id), jautaajuma_kateid, kategorijas_img, kategorijas_nosaukums, kategorijas_apraksts, kategorijas_id FROM $tbl_name JOIN $tb2_name ON $tb2_name.jautaajuma_kateid=$tbl_name.kategorijas_id WHERE jautaajuma_kateid = kategorijas_id GROUP BY jautaajuma_kateid ORDER BY kategorijas_id DESC Edited January 5, 2009 by goma smile Link to comment Share on other sites More sharing options...
bubu Posted January 5, 2009 Report Share Posted January 5, 2009 Taisi LEFT JOIN. Link to comment Share on other sites More sharing options...
Gints Plivna Posted January 5, 2009 Report Share Posted January 5, 2009 Yeahh <uzbrauciens>: Latviešu valodā ir tāda pieturzīme, kas saucās jautājuma zīme un kuru raksta šādi "?". Tā palīdz saprast tādu niansi, vai konkrētais izteikums ir jautājums, vai, piemēram, apgalvojums, ko, nedzirdot Tavu runas intonāciju, ir visai grūti citādi saprast. </uzbrauciens> Tagad par lietu - Tev interesē ārējais savienojums, kurš ir viens no savienojumu veidiem un atšķirīgs no iekšējā savienojuma, ko Tu izmanto savā SQL Select teikumā. Gints Plivna http://datubazes.wordpress.com Link to comment Share on other sites More sharing options...
goma smile Posted January 5, 2009 Author Report Share Posted January 5, 2009 arī LEFT JOIN neko nemaina Link to comment Share on other sites More sharing options...
bubu Posted January 6, 2009 Report Share Posted January 6, 2009 Nu tad palasi Ginta dotos linkus. Link to comment Share on other sites More sharing options...
anonīms Posted January 6, 2009 Report Share Posted January 6, 2009 no mana koda, kuru arī ieguvu php.lv $pcnt3 = mysql_query("SELECT COUNT(gamefarm_forums_atbildes.id) AS skaits FROM gamefarm_forums_atbildes, gamefarm_forums_topiki WHERE gamefarm_forums_atbildes.topika_id = gamefarm_forums_topiki.id AND gamefarm_forums_topiki.kategorijas_id = $forums[0]") or die(mysql_error()); Link to comment Share on other sites More sharing options...
Grey_Wolf Posted January 6, 2009 Report Share Posted January 6, 2009 (edited) Taisi LEFT JOIN. LEFT JOIN nenostradaas ja otraa tabulaa pretii nebuus ieraksta ... parbaudiits praksee ... (kautgan ikaa vajadzeetu atgriest, bet nu Mysql 4.1.xx toch netgriezj ) Jaizmanto konstrukcija LEFT OUTER JOIN tad gan var izmantot count(tabulas_id_kur_komentari) un grupeet peec pirmaas tabulas .. --- edit: nepaskatijos Gints jau to bija uzradijis... Edited January 6, 2009 by Grey_Wolf Link to comment Share on other sites More sharing options...
codez Posted January 6, 2009 Report Share Posted January 6, 2009 (edited) Varbūt labāk topics tabulā glabāt lauku atbilžu_skaits, un, kad pievieno atbildi palielināt, vai kad izdzēš atbildi samazināt. Gan ātrāk strādās, gan vienkāršāks kverijs? Edited January 6, 2009 by codez Link to comment Share on other sites More sharing options...
goma smile Posted January 6, 2009 Author Report Share Posted January 6, 2009 es palasiju ginta majaslapa un provēju visus JOIN veidus bet nekas nesanāk vienalga nerāda sadaļu kurā nav iekšā neviena topika Link to comment Share on other sites More sharing options...
bubu Posted January 6, 2009 Report Share Posted January 6, 2009 LEFT JOIN nenostradaas LEFT JOIN ļoti labi strādās, vajag tik atcerēties, ka COUNT neskaita NULL vērtības. mysql> use test; Database changed mysql> create table sadaljas (id int, nosaukums varchar(50)); Query OK, 0 rows affected (0.00 sec) mysql> create table forumi (id int, sadaljas_id int, nosaukums varchar(50)); Query OK, 0 rows affected (0.01 sec) mysql> insert into sadaljas values (1, "php"); Query OK, 1 row affected (0.00 sec) mysql> insert into sadaljas values (2, "java"); Query OK, 1 row affected (0.00 sec) mysql> insert into sadaljas values (3, "sql"); Query OK, 1 row affected (0.00 sec) mysql> insert into forumi values (1, 1, "php nuubiem"); Query OK, 1 row affected (0.00 sec) mysql> insert into forumi values (2, 1, "php ne-nuubiem"); Query OK, 1 row affected (0.00 sec) mysql> insert into forumi values (3, 3, "mysql"); Query OK, 1 row affected (0.00 sec) mysql> insert into forumi values (4, 3, "postgresql"); Query OK, 1 row affected (0.00 sec) mysql> insert into forumi values (5, 3, "oracle"); Query OK, 1 row affected (0.00 sec) mysql> select sadaljas.nosaukums, COUNT(forumi.id) FROM sadaljas LEFT JOIN forumi ON sadaljas.id = forumi.sadaljas_id GROUP BY sadaljas.nosaukums; +-----------+------------------+ | nosaukums | COUNT(forumi.id) | +-----------+------------------+ | java | 0 | | php | 2 | | sql | 3 | +-----------+------------------+ 3 rows in set (0.00 sec) Link to comment Share on other sites More sharing options...
goma smile Posted January 6, 2009 Author Report Share Posted January 6, 2009 (edited) Ja ir vaina bija ka bija WHERE paldies a kāds nezinātu kā var apreiķināt atbilžu skautu katrā sadaļā Edited January 6, 2009 by goma smile Link to comment Share on other sites More sharing options...
bubu Posted January 6, 2009 Report Share Posted January 6, 2009 Tieši tāpat. Link to comment Share on other sites More sharing options...
Recommended Posts