I want to get all players from a football club and filter those out that are from Germany, I know that it is possible without the filter option, but I'm new to SPARQL and it seems that i don't understand how to use the filter option in that case, so I would be glad if someone could tell a way how to get that working.
SELECT distinct ?player WHERE {
?player a <http://dbpedia.org/ontology/SoccerPlayer>.
?player <http://dbpedia.org/property/currentclub> <http://dbpedia.org/resource/Hertha_BSC>.
optional {?subject <http://dbpedia.org/ontology/birthPlace>/<http://dbpedia.org/ontology/country> ?<http://dbpedia.org/resource/Germany>. }
filter (!bound(?subject)).
}
ORDER BY ASC(?player)
best regards Adrian
I hope you are looking for something like this:
SELECT distinct ?player WHERE {
?player a dbo:SoccerPlayer .
?player dbp:currentclub dbr:Hertha_BSC .
?player dbo:birthPlace/dbo:country? ?country .
FILTER (?country = dbr:Germany)
}
ORDER BY ASC(?player)
Or this:
SELECT distinct ?player WHERE {
?player a dbo:SoccerPlayer .
?player dbp:currentclub dbr:Hertha_BSC .
?player dbo:birthPlace/dbo:country? ?country .
FILTER (?country in (dbr:Germany))
}
ORDER BY ASC(?player)
Or even this:
SELECT distinct ?player WHERE {
?player a dbo:SoccerPlayer .
?player dbp:currentclub ?club .
?player dbo:birthPlace/dbo:country? ?country .
VALUES (?club ?country) { (dbr:Hertha_BSC dbr:Germany) }
}
ORDER BY ASC(?player)
Related
In my project I managed to do a search via request and I wanted to do a search filtered by name (in this case already) and also by reference.
I looked on the internet and nothing that helps me up so far.
I appreciate your help:\
else {
$valida=2;
$produtc = Produtos::where('nome' & 'refencia', 'like', "%{$tpesquisa}%")->paginate();
$nrr = count($produtos);
$msgm = 'Pesquisa concluida com sucesso, foram econtrados ' .$nrr. ' resultados';
return view('pesquisa', compact('produtc', 'msgm', 'nrr', 'valida'));
You are doing it wrong please try with the following way.
else {
$valida=2;
$produtc = Produtos::where('nome', 'like', "%".$tpesquisa."%")->orWhere('refencia','like', "%".$tpesquisa."%")->paginate();
$nrr = count($produtos);
$msgm = 'Pesquisa concluida com sucesso, foram econtrados ' .$nrr. ' resultados';
return view('pesquisa', compact('produtc', 'msgm', 'nrr', 'valida'));
If you want to do it using AND operator then use following code.
else {
$valida=2;
$produtc = Produtos::where('nome', 'like', "%".$tpesquisa."%")->where('refencia','like', "%".$tpesquisa."%")->paginate();
$nrr = count($produtos);
$msgm = 'Pesquisa concluida com sucesso, foram econtrados ' .$nrr. ' resultados';
return view('pesquisa', compact('produtc', 'msgm', 'nrr', 'valida'));
Give this a try I use this when ever i need to do a search
Produtos::where(function ($query){
$query->orWhere('nome', 'LIKE', "%". $tpesquisa. "%")
->orWhere('refencia', 'LIKE', "%". $tpesquisa. "%");
})
->paginate();
I need some help to write my update query.
DELETE {
?contactInfo vivo:freeTextValue5 ?o .
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
Can you please let me know what is wrong with this "update" query?
I'm guessing that your problem is that this update adds a new triple, but does not remove the old one.
The reason is that your DELETE clause contains an unbound variable: ?o. This is not allowed - or at least what happens is that patterns with unbound variables are simply ignored by the SPARQL engine. So your DELETE won't actually remove any triples. The variable ?o needs to be bound to a value in your WHERE clause.
One way to fix this is to just replace ?o with the specific value:
DELETE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
More generally, you can use a VALUES clause to bind ?o to a value, like this:
DELETE {
?contactInfo vivo:freeTextValue5 ?o.
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
VALUES ?o { "old_url"^^<http://www.w3.org/2001/XMLSchema#string> }
?contactInfo vivo:freeTextValue5 ?o.
}
This is perhaps the better approach as it makes it easier to extend your update to different values for ?o.
How to prevent auto fix in the select statement using CodeIgniter 3?
Query that I want: SELECT REPLACE(item, ',', '') AS item (without space)
I tried : $this->db->select("replace(item, ',', '') AS item", FALSE);
Result : SELECT REPLACE(item, ', ', '') AS item (CI added a space in my query)
I read this documentation but it didn't work.
This my real query:
$this->db->select("a.unit_id");
$this->db->select("replace(c.topik, ',', '') AS topik", FALSE); //this my problem (added space which shouldnt)
$this->db->select("COUNT(*) AS jumlah");
$this->db->from('opub_kliping a');
$this->db->join('opub_media b','a.media_id = b.organisasi_id');
$this->db->join('opub_tag c','a.id = c.kliping_id');
if(!empty($data['keyword']))$this->db->where("(a.judul LIKE '%".$data['keyword']."%' OR a.text LIKE '%".$data['keyword']."')");
if(!empty($data['tgl1']))$this->db->where("a.tanggal >=",$data['tgl1']);
if(!empty($data['tgl2']))$this->db->where("a.tanggal <=",$data['tgl2']);
if(!empty($data['unit']))$this->db->where("a.unit_id ",$data['unit']);
if(!empty($data['media']))$this->db->where("a.media_id ",$data['media']);
if(!empty($data['jenis']))$this->db->where("a.jenis_id ",$data['jenis']);
if(!empty($data['tone']))$this->db->where("a.karakter ",$data['tone']);
if(!empty($data['topik']))
{
$qTopik = array();
$expTopik = explode(',', $data['topik']);
foreach($expTopik as $t)
{
if(!empty($t))
{
$qTopik[] = "c.topik LIKE '%$t%'";
}
}
if(!empty($qTopik))
{
$qTopiks = implode(",", $qTopik);
$this->db->where($qTopiks);
}
}
$this->db->where('a.unit_id !=', 0);
$this->db->where('c.topik !=', NULL);
$this->db->where('c.topik !=', '');
$this->db->group_by("a.unit_id");
$this->db->group_by("replace(c.topik, ',', '')", FALSE); //this produce correct query (without adding space)
$this->db->order_by('a.unit_id', 'ASC');
$this->db->order_by('jumlah', 'DESC');
$q= $this->db->get();
i found this after tried some experiment
$this->db->select(array('REPLACE(c.topik', "','", "'') AS topik"), false);
seems little hack maybe. but its work for me
hope will help others
change 4 lines of your query
$this->db->select("a.unit_id,replace(c.topik, ',', '') AS topik,COUNT(*) AS jumlah")->from('opub_kliping a');
$this->db->join('opub_media b','a.media_id = b.organisasi_id');
I have four tables I need to join in query build
function get_debtors( ) {
$this->db->select('invoice.student_id as STUDENT_ID,student.name AS
STUDENT_NAME,section.name AS CLASS,
invoice.description AS DESCRIPTION,
invoice.amount AS TOTAL_AMOUNT,
invoice.amount_owed AS AMOUNT_OWED,
parent.name AS PARENT_NAME,
parent.email AS PARENT_EMAIL,
parent.phone AS PARENT_PHONE,
parent.address AS PARENT_ADDRESS,
invoice.status AS STATUS');
$this->db->from('invoice , student , parent , section ');
$this->db->join('student ', 'student.student_id = invoice.student_id');
$this->db->join('parent ', 'parent.parent_id = student.parent_id, 'left'');
$this->db->join('section ', 'section.section_id = student.section_id','left');
$this->db->where('invoice.status', 'debtor');
$query = $this->db->get();
Try this. If there is still any error than post the error also here.
function get_debtors( )
{
$this->db->select('invoice.student_id as STUDENT_ID,student.name AS
STUDENT_NAME,section.name AS CLASS,
invoice.description AS DESCRIPTION,
invoice.amount AS TOTAL_AMOUNT,
invoice.amount_owed AS AMOUNT_OWED,
parent.name AS PARENT_NAME,
parent.email AS PARENT_EMAIL,
parent.phone AS PARENT_PHONE,
parent.address AS PARENT_ADDRESS,
invoice.status AS STATUS');
$this->db->from('invoice');
$this->db->join('student ', 'student.student_id = invoice.student_id');
$this->db->join('parent ', 'parent.parent_id = student.parent_id', 'left');
$this->db->join('section ', 'section.section_id = student.section_id','left');
$this->db->where('invoice.status', 'debtor');
$query = $this->db->get();
}
I wanted to select two columns and display it as one in my controller. Here is the code I currently have:
public function assignment()
{
$title = "View Parent Assignment";
$vpc = DB::table('dbo_guardianchild')
->join('dbo_students', 'dbo_guardianchild.StudentID', '=' , 'dbo_students.StudentID')
->join('dbo_guardianinformation' , 'dbo_guardianchild.GuardianInformationID' , '=' , 'dbo_guardianinformation.GuardianInformationID')
->select('dbo_students.StudentID' , 'dbo_students.FirstName AS sFname' , 'dbo_students.LastName AS sLname')
->get();
}
Any ideas on how I can combine the dbo_students.FirstName and dbo_students.LastName into one column?
You should try DB::raw. Try replacing the code in select as
->select(DB::raw('dbo_students.StudentID' ,'CONCAT(dbo_students.FirstName, " ", dbo_students.LastName) AS full_name'))
And your final code will be
public function assignment()
{
$title = "View Parent Assignment";
$vpc = DB::table('dbo_guardianchild')
->join('dbo_students', 'dbo_guardianchild.StudentID', '=' , 'dbo_students.StudentID')
->join('dbo_guardianinformation' , 'dbo_guardianchild.GuardianInformationID' , '=' , 'dbo_guardianinformation.GuardianInformationID')
->select(DB::raw('dbo_students.StudentID' ,'CONCAT(dbo_students.FirstName, " ", dbo_students.LastName) AS full_name'))
->get();
}