Jump to content
php.lv forumi

multidimensionla tabula


ray

Recommended Posts

Pieņemsim, ka man ir jaunumu tabula (id, date, title, author) un autoru tabula (id, name). No šīm tabulām vajadzētu izgūt datus, par to cik katrs autors katrā mēnesī ir uzrakstījis rakstus. Tabulas izkārtojums būtu matrica, ka augšā ir mēnesis (+ gads), bet kreisajā kolonnā autora vārds (name) un attiecīgi pret vārdu un mēnesi skaits (cik raksti šajā mēnesī attiecīgajam autoram).

Kā kaut ko šādu varētu realizēt?

Link to comment
Share on other sites

http://saveabend.blogspot.com/2006/10/mysql-crosstabs.html

 

varētu sanākt kaut kas tāds(nav testēts):

 

SELECT 
autori.name as autors,
SUM(IF ( MONTH(jaunumi.date) = '1', 1, 0 )) as janvaris_2010
SUM(IF ( MONTH(jaunumi.date) = '2', 1, 0 )) as februaris_2010
SUM(IF ( MONTH(jaunumi.date) = '3', 1, 0 )) as marts_2010
FROM jaunumi
JOIN autori ON jaunumi.author = autori.id
GROUP BY (autori.name)
WHERE YEAR(jaunumi.date) = 2010

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...