[S] SQL Code

resoucer

Gesperrt
ID: 77379
L
20 April 2006
2.846
109
Hi, wollte mal fragen ob mir wer nen helfen kann ein SQl Query zu coden der folgende funktion hat

Code:
CREATE TABLE `pics` (
  `id` int(11) NOT NULL auto_increment,
  `autor` varchar(255) collate latin1_general_ci NOT NULL,
   `b1` int(10) NOT NULL default '0',
  `b2` int(10) NOT NULL default '0',
  `b3` int(10) NOT NULL default '0',
  `b4` int(10) NOT NULL default '0',
  `b5` int(10) NOT NULL default '0',
  `b6` int(10) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM;

CREATE TABLE `videos` (
  `id` int(11) NOT NULL auto_increment,
  `autor` varchar(255) collate latin1_general_ci NOT NULL,
   `b1` int(10) NOT NULL default '0',
  `b2` int(10) NOT NULL default '0',
  `b3` int(10) NOT NULL default '0',
  `b4` int(10) NOT NULL default '0',
  `b5` int(10) NOT NULL default '0',
  `b6` int(10) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM;

Undzwar möchte ich die autoren ordnen nach deren Durchschnittsbewertung
b1 = note 1; b2 = note2 usw.
und beide tabellen sollen zusammengerechnet werden, so in etwa
((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6);

das ist aber nur für 1 Tabelle dann.

Hoffe mir kann da einer helfen und ich habe alles richtig ausgedrückt.

mfg
 
hmm, was genau soll das für ein bewertungssystem sein?

note 1 bis 6, und die note die gegeben wurde, wird in der db um eines erhöht?

warum machst du nicht eine spalte für die note und eine für die anzahl der stimmen? oder brauchst du stehts die genau anzahl, welche note wie oft gegeben wurde?



Ansonsten probiers mal so:

SELECT id, author, ((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6) note, 'pics' type
FROM pics
UNION
SELECT id, author, ((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6) note, 'movs' type
FROM videos
ORDER BY note

 
SELECT id, author, ((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6) note, 'pics' type
FROM pics
UNION
SELECT id, author, ((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6) note, 'movs' type
FROM videos
ORDER BY note


schein soweit zu funzen, problem ist nur das die die keine bewertung haben ganz oben stehen, da 0 < 1 ist (logisch) muss irgendwie noch dahin machen where note > 0 aber das klappt ja so nicht
 
was macht dich so sicher, dass es nicht funktionieren wird?

*evt noch nen kleiner tip, speichere die "note" in einer eigenen spalte bei jeder neuen bewertung. sonst legst du auf dauer die datenbank lahm. :)
 
was macht dich so sicher, dass es nicht funktionieren wird?

*evt noch nen kleiner tip, speichere die "note" in einer eigenen spalte bei jeder neuen bewertung. sonst legst du auf dauer die datenbank lahm. :)

weil note nicht bekannt ist

Unknown column 'note' in 'where clause'
Code:
SELECT titel,id, autor, ((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6) note, 'pics' type
FROM pics where note > 0
UNION
SELECT id, titel, autor, ((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6) note, 'movs' type
FROM videos where note > 0
ORDER BY note asc LIMIT 50
 
SELECT id, author, ((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6) note, 'pics' type
FROM pics HAVING note>0
UNION
SELECT id, author, ((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6) note, 'movs' type
FROM videos HAVING note>0
ORDER BY note

 
SELECT id, author, ((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6) note, 'pics' type
FROM pics HAVING note>0
UNION
SELECT id, author, ((1*b1)+(2*b2)+(3*b3)+(4*b4)+(5*b5)+(6*b6)) / (b1+b2+b3+b4+b5+b6) note, 'movs' type
FROM videos HAVING note>0
ORDER BY note


klappt thx