snach15 Posted October 15, 2010 Report Share Posted October 15, 2010 tātad turpinot visu apgūt atkal aizķēros aiz divām lietām kurām neredzu risinājumu 1. izsaucu no MSSQL datubāzes -no colonas (flags) visas valstis, bet kā lai uztaisa takā topu to visu tagad? piemēram man datubāzē ir vairākiem latvia, vairāk english, un vairākiem kautvai azarbaidžāna .. kā varu latvia salikt takā vienā kopā un uzrādīt skaitu cik tādu ir? un attiecīgi pēc flagiem kas sakrīt arī sarindot to visu .. 2. veidoju statistiku un gribu uztaisīt kad var redzēt cik reģistrējušies ir šodien, tātad no 00:00 - 23:59 .. kā to izdarīt ? ar laikiem neko nēesmu pēries un lasot tutorial grūti saprast kā šo scriptu var realizēt .. Quote Link to comment Share on other sites More sharing options...
reiniger Posted October 15, 2010 Report Share Posted October 15, 2010 Parādi nedaudz savas datubāzes struktūru... Quote Link to comment Share on other sites More sharing options...
snach15 Posted October 15, 2010 Author Report Share Posted October 15, 2010 Quote Link to comment Share on other sites More sharing options...
reiniger Posted October 15, 2010 Report Share Posted October 15, 2010 (edited) Šis ir no MYSQL Varētu palīdzēt saistībā uz pirmo jautājumu SELECT country, COUNT(ID) FROM tabula GROUP by country ORDER by country ASC 2 jautajuma ja reg_date_time tips ir time, ja datetime tad TIME(reg_date_time) SELECT * FROM tabula WHERE reg_date_time > '00:00:00' AND reg_date_time <= TIME(NOW()) Edited October 15, 2010 by reiniger Quote Link to comment Share on other sites More sharing options...
snach15 Posted October 15, 2010 Author Report Share Posted October 15, 2010 (edited) galīgi neiebraucu kas būtu ta cound(id) ? kautkāda collona vēl? $test = mssql_query("SELECT country FROM memb_info GROUP by country ORDER by country ASC"); $test2= mssql_fetch_array($test); $test2 = $test2[0]; reku tā tas izkatītos bet man tagad viņs parāda tikai vienu eng un vis .. Edited October 15, 2010 by snach15 Quote Link to comment Share on other sites More sharing options...
Gints Plivna Posted October 15, 2010 Report Share Posted October 15, 2010 select top n count(*) cnt, country from tabula group by country order by cnt desc n - cik ierakstus gribi redzēt select count(*) from tabula where datuma_lauks > DATEADD(dd, DATEDIFF(dd,0,GETDATE()), 0) otrais izskatās nenormāli tizli, piekrītu, bet AFAIK SQL Serverī nav normāla veida kā eleganti nogriezt laika daļu datumam Gints Plivna http://datubazes.wordpress.com Quote Link to comment Share on other sites More sharing options...
snach15 Posted October 15, 2010 Author Report Share Posted October 15, 2010 (edited) idēali paldies .. kautkas izdevās tikai tagad to skaitu vajg .. jeb ideālā variantā procentuāli norādīt .. cods izkatās šādi $query = mssql_query("SELECT top 10 country FROM MEMB_INFO group by country order by country desc"); while($qr = mssql_fetch_array($query)){ echo "<tr align=center> <td></td> <td>$qr[country]</td> </tr>";} vis ok . Edited October 15, 2010 by snach15 Quote Link to comment Share on other sites More sharing options...
Gints Plivna Posted October 15, 2010 Report Share Posted October 15, 2010 (edited) Lasīt mākam? Nu tad sākam! ;) Tas ko Tu esi uzrakstīji savā php kodā nav tas ko es tev uzrakstīju. Šeit nav daiļliteratūra un cnt un country ir 2 dažādas lietas. Procentuāli (pirmā kolona skaits, otrā procents, trešā valsts): SELECT TOP n cnt, cnt/cast(total as float)*100, country FROM ( SELECT count(*) cnt, country FROM tabula GROUP BY country ) as t CROSS JOIN ( SELECT COUNT(*) total FROM tabula ) as t1 ORDER BY cnt DESC TUR TAGAD IR 3 KOLONAS un arī PIRMS TAM BIJA 2, no kurām vienā bija skaits Gints Plivna http://datubazes.wordpress.com Edited October 15, 2010 by Gints Plivna Quote Link to comment Share on other sites More sharing options...
snach15 Posted October 15, 2010 Author Report Share Posted October 15, 2010 (edited) bet kā tagad parādīt tos procentus? sarežģīts šis sql scripts tagad ir ko uzrakstīji, nevaru saprast viņa nozīmi tāpēc ar nemāku izvadīt procentus .. $query = mssql_query("SELECT TOP 10 cnt, cnt/cast(total as float)*100, country FROM ( SELECT count(*) cnt, country FROM MEMB_INFO GROUP BY country ) as t CROSS JOIN ( SELECT COUNT(*) total FROM MEMB_INFO ) as t1 ORDER BY cnt DESC"); while($qr = mssql_fetch_array($query)){ echo "<tr align=center> <td>$gr[procenti]</td> <td>$qr[country]</td> </tr>";} Edited October 15, 2010 by snach15 Quote Link to comment Share on other sites More sharing options...
Gints Plivna Posted October 15, 2010 Report Share Posted October 15, 2010 SELECT TOP 10 cnt, cnt/cast(total as float)*100 AS per_cent, country Kolonas: cnt - skaits per_cent - noaliasoju, procenti country - valsts Principā jau nu nekas īpaši sarežģīts tur nav, vismaz kolonas aizstājējvārdu (alias) vajadzētu mācēt pielikt, tas rakstīts piemēram šeit http://datubazes.wordpress.com/2007/12/28/sql-select-i/'>http://datubazes.wordpress.com/2007/12/28/sql-select-i/ Gints Plivna http://datubazes.wordpress.com Quote Link to comment Share on other sites More sharing options...
snach15 Posted October 15, 2010 Author Report Share Posted October 15, 2010 un kā tos drausmīgos skaitļus aiz komantiem var noņemt? Quote Link to comment Share on other sites More sharing options...
Gints Plivna Posted October 15, 2010 Report Share Posted October 15, 2010 Formatējot. Un to var izdarīt gan SQL Server galā, gan php galā. Tikai ar tik triviālām tak spēsi galā tikt pats, vai ne?`;) Quote Link to comment Share on other sites More sharing options...
snach15 Posted October 15, 2010 Author Report Share Posted October 15, 2010 mēgināts nav zaudēts ;) nu paldies par visu šito .. reti kad te var tādu palīdzību saņemt :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.