How do I query database facts with 3 or more attributes in Prolog using bagof
, setof
. An example I have a defined a database students(name, grade,sport,gender)
. I want find a list of students that play a particular sport, say cricket. My current query
sport_list(L):-
bagof(S,N^G^D^students(N,G,S,D),L),
S = cricket.
student(patash,5,rugby,male).
student(naomi,3,netball,female).
student(lepo,6,_,male).
student(diamal,4,cricket,male).
student(bonga,5,chess,female).
student(imi,6,cricket,male).
student(ayanda,3,_,female).