Autor Beitrag
blackbirdXXX

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: Sa 28.05.05 11:36 
Also ich habe folgenden SQL Befehl:
ausblenden Quelltext
1:
2:
SELECT IF (poster_id = 299 AND topic_id = 1663,  "JA", "NEIN")
AS myself FROM ubuntu_posts WHERE topic_id = 1663 LIMIT 0,100

Kriege ich folgendes Ergebnis:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
JA
NEIN
NEIN
NEIN
NEIN
NEIN

Das stimmt auch: --> www.ubuntuusers.de/forum/topic/1663 (User 299 bin ich)

Ich hätte aber gerne, dass er mir JA ausgibt, wenn ich irgendwann mal in dem Post vorkomme NEIN, wenn ich das nicht tue.
Und nicht für jeden Post eine Zeile.

Wie funktioniert das?

_________________
Klein, schwarz und ärgert Techniker? Jumper!
inselberg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458



BeitragVerfasst: So 29.05.05 02:27 
select distinct ...

wenn ich richtig verstanden habe was du meinst

_________________
hans bist du das ?
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 29.05.05 08:06 
Bei 'select distinct' bekommt man alle unterschiedlichen Zeilen. Hier wären das 2, nämlich 'JA' und 'NEIN'. Was Du willst, ist gar nicht so einfach, weil Du auch eine Antwort willst, wenn Du *nicht* in der Ergebnismenge enthalten bist. Wenn Du nur wissen willst, ob Du drin bist, versuch doch das hier:
ausblenden Quelltext
1:
2:
select IF (topic_id = 1663,  "JA", "NEIN")
AS myself FROM ubuntu_posts WHERE poster_id = 299 AND topic_id = 1663 LIMIT 0,100

Ich kenne diesen SQL-Dialekt nicht (mySQL?), ich verwende MS SQL Um hier eine JA/NEIN Antwort zu bekommen, würde ich folgendes machen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
select
  case when 
    exists (select * from ubuntu_posts WHERE poster_id = 299 AND topic_id = 1663) 
  then 'JA' 
  else 'NEIN' 
  end

Wenn es also die gesuchte Zeile gibt, dann liefere 'JA' sonst 'NEIN'. Geht das mit deinem SQL?
blackbirdXXX Threadstarter

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: So 29.05.05 19:00 
user profile iconalzaimar hat folgendes geschrieben:
ausblenden Quelltext
1:
2:
select IF (topic_id = 1663,  "JA", "NEIN")
AS myself FROM ubuntu_posts WHERE poster_id = 299 AND topic_id = 1663 LIMIT 0,100


Das hab ich schon gehabt. Aber da krieg ich für jeden Post, den ich in dem Thread geschreiben habe ein JA, ich will aber nur eines insgesamt.

user profile iconalzaimar hat folgendes geschrieben:
Ich kenne diesen SQL-Dialekt nicht (mySQL?), ich verwende MS SQL Um hier eine JA/NEIN Antwort zu bekommen, würde ich folgendes machen:

Kein Dialekt. Sollte allgemeines SQL sein.

_________________
Klein, schwarz und ärgert Techniker? Jumper!
blackbirdXXX Threadstarter

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: Di 31.05.05 20:45 
Keiner eine Idee?
Ich brauche das um in der Forenübersicht Beiträge, in denen ein bestimmter Benutzer vorkommt hervorzuheben.

_________________
Klein, schwarz und ärgert Techniker? Jumper!
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 31.05.05 20:56 
guck mal nach HAVING.

_________________
Gruß
Hansa
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Di 31.05.05 21:30 
@blackbirdXX: mySQL = ANSI-SQL? Weiss ich nicht. Ich weiss nur: MSSQL<>ANDI SQL, aber egal.

Du willst also ein einziges JA, wenn poster 299 in thread 1633 ist? Na, dann gehts mit
ausblenden Quelltext
1:
2:
3:
4:
select distinct 
  IF (topic_id = 1663,  "JA", "world is a disc") AS myself 
FROM ubuntu_posts 
WHERE poster_id = 299 AND topic_id = 1663
blackbirdXXX Threadstarter

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: Di 31.05.05 21:34 
user profile iconhansa hat folgendes geschrieben:
guck mal nach HAVING.

Danke. Das dürfte funktionieren.

_________________
Klein, schwarz und ärgert Techniker? Jumper!
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Di 31.05.05 21:40 
"HAVING" geht doch nur mit Aggregaten? Na, bin mal gespannt :wink:
blackbirdXXX Threadstarter

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: Mi 01.06.05 04:51 
user profile iconalzaimar hat folgendes geschrieben:
@blackbirdXX: mySQL = ANSI-SQL? Weiss ich nicht. Ich weiss nur: MSSQL<>ANDI SQL, aber egal.

Du willst also ein einziges JA, wenn poster 299 in thread 1633 ist? Na, dann gehts mit
ausblenden Quelltext
1:
2:
3:
4:
select distinct 
  IF (topic_id = 1663,  "JA", "world is a disc") AS myself 
FROM ubuntu_posts 
WHERE poster_id = 299 AND topic_id = 1663


Wunderbar. Das ist genau das, was ich wollte :D

_________________
Klein, schwarz und ärgert Techniker? Jumper!
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Mi 01.06.05 10:38 
Du kannst wohl die allerersten Anworten nicht lesen ? :rofl:

_________________
Gruß
Hansa
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Mi 01.06.05 15:56 
Doch, kann er. Aber beim ersten Ansatz kamen immer zwei Zeilen raus, nämlich JA und NEIN. Super, eine sog. Tautologie. :beer:
blackbirdXXX Threadstarter

ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1077
Erhaltene Danke: 1

Ubuntu Dapper

BeitragVerfasst: Mi 01.06.05 17:07 
user profile iconhansa hat folgendes geschrieben:
Du kannst wohl die allerersten Anworten nicht lesen ? :rofl:

kannte select distinct nicht. jetzt, mit dem beispiel bin ich natürlich schlauer :D

_________________
Klein, schwarz und ärgert Techniker? Jumper!