I would like to exclude all ?Resultat that are 0.0. So I would need some kind of Filter that says ?FakturierterUmsatz != ?SummeVerbuchterAufwand.
I tried a couple of things (new to SPARQL) but nothing seems to work.
Can anyone help me with this problem?
SELECT DISTINCT
?Projekt
(SUM(distinct?FakturierterUmsatz) as ?SummeFakturierterUmsatz)
(SUM(distinct ?VerbuchterAufwand) as ?SummeVerbuchterAufwand)
(?FakturierterUmsatz - ?SummeVerbuchterAufwand as ?Resultat)
WHERE
{
?Projekt <http://itopia.ch/iOntology/hasAbrechnung> ?Abrechnung.
?Abrechnung <http://itopia.ch/iOntology/FakturierterUmsatz> ?FakturierterUmsatz.
?Abrechnung <http://itopia.ch/iOntology/VerbuchterAufwand> ?VerbuchterAufwand .
?Abrechnung <http://itopia.ch/iOntology/hasKunde> ?Kunde.
}
GROUP BY ?Projekt ?FakturierterUmsatz
Actually I tried it with the following solution and it seems to work:
HAVING (?FakturierterUmsatz - ?SummeVerbuchterAufwand != 0)
Related
I need to get the data from a DB and match two columns: Key and name, but I cant get it to work, if I use AND on both conditions:
...where lower(items.key_) SIMILAR TO lower('memory.size')
and lower(items.name) SIMILAR TO lower('Memory Utilization%')
and history.clock > '2020-08-12 03:05:32'
the query doesnt work because when items.key is similar to memory.size, items.name will never be similar to "Memory Utilization", so I try to do it with OR:
...where lower(items.key_) SIMILAR TO lower('memory.size')
or lower(items.name) SIMILAR TO lower('Memory Utilization%')
and history.clock > '2020-08-12 03:05:32'
But it doesnt work either.
Any Ideas?
SIMILAR TO is not really the operator you want. You are using %, so that suggests LIKE:
where (lower(items.key_) like lower('memory.size') or
lower(items.name) like lower('Memory Utilization%')
) and history.clock > '2020-08-12 03:05:32'
I using Laravel and its \Illuminate\Database\Eloquent\Builder. I would like to select all columns from "table_1" a have custom column "is_table_2_present" which value will be 1 or 0 depending if(table_1_id != null).
So I would like to do something like that.
$queryBuilder->leftJoin("table_2"....)
$queryBuilder->select([
"table_1.*",
"is_table_2_present" = (table_2_id != null) ? 1 : 0,
]);
I was trying to search for an answer but without much of a success. So I would like to ask if something like that is possible?
The reason why I cannot use Eloquent relationship is because I would need relationship with parameter. And that not possible in laravel 5.2 right?
public function table_2($userId)
{
return $this->hasOne(Table_2::class....)->where(user_id, "=", userId);
}
Conceptually each table is associated to a model. Try eloquent relationship between the models of the two table you are trying to query.
You can use selectRaw(), I think it will be:
$queryBuilder->selectRaw(
<<<EOT
table_1.*,
if(table_2_id != ?, 1, 0) as is_table_2_present,
EOT,
[null]
);
In the above code, I used binding to avoid the SQL injection.
Since this question kinda died, no respons for a while I solved it with selectRaw() for now. But still in search for more neat solution.
$queryBuilder->selectRaw("
table_one.*,
CASE WHEN table_two.id IS NOT NULL THEN 1 ELSE 0 END AS tableTwoPresent
");
I'm testing SPARQL with Protégé on this data file
https://raw.githubusercontent.com/miranda-zhang/cloud-computing-schema/master/example/sparql-generate/result/gcloud_vm.ttl
Validated the following works:
PREFIX cocoon: <https://raw.githubusercontent.com/miranda-zhang/cloud-computing-schema/master/ontology_dev/cocoon.ttl>
SELECT ?VM ?cores
WHERE {
?VM a cocoon:VM ;
cocoon:numberOfCores ?cores .
}
For example, it returns something like:
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-ULTRAMEM-80-PREEMPTIBLE "80"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-64-PREEMPTIBLE "64"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-2 "2"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-F1-MICRO "shared"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-8-PREEMPTIBLE "8"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-HIGHCPU-32 "32"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-HIGHMEM-16-PREEMPTIBLE "16"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-96-PREEMPTIBLE "96"#
https://w3id.org/cocoon/data/vm/gcloud/CP-COMPUTEENGINE-VMIMAGE-N1-STANDARD-4 "4"#
I'm not sure if I can apply a filter on ?cores, I tried the following, but they returned nothing:
cocoon:numberOfCores "shared" .
Or
FILTER(?cores = "4") .
I'd also like to apply filter on ?cores (i.e. > 4 and < 8), so I have to make it an xsd:integer? But then I have to get rid of shared which is about < 1 core
Thanks AKSW, impressive knowledge about Protégé.
In the end, I changed my data type to xsd:decimal. Seems to be enough for now.
My final goal is I want to get plid and portletId that can be display my article(or entry with any type if it is possible).
I have sql query that return me any portlet availble for display my article.
But when I have to use dynamicQuery to get the same results, I get problem with xPath and array comparison, please help!
SELECT * FROM portletpreferences pr
WHERE pr.preferences != '<portlet-preferences />' AND pr.ownerid = 0 AND pr.portletid ilike '%_INSTANCE_%' AND pr.plid IN(
SELECT layout.plid FROM layout
WHERE layout.type_ = 'portlet' AND layout.groupid = 19 AND layout.hidden_ is false)
AND pr.portletpreferencesid IN (
SELECT pr.portletpreferencesid FROM portletpreferences pr
WHERE 'true' = ANY(xpath('//preference[name="anyAssetType"]/value/text()', XMLPARSE(DOCUMENT pr.preferences))::text[])
OR (SELECT (array(SELECT id_ FROM journalstructure))::text[]) && xpath('//preference[name="classTypeIds"]/value/text()', XMLPARSE(DOCUMENT pr.preferences))::text[] )
If you are bent upon using this same query, then use this query directly with Custom-SQL in liferay by creating custom-finders instead of using DynamicQuery. That would give you a lot of flexibility in using any type of SQL query directly.
I don't think this query can be converted to DynamicQuery, but if you do manage to convert it then please do post it here :-)
DynamicQuery is very powerful, see e.g. my answer how to find layouts with specific JournalArticles. I think your requirement is similar to this one:
Liferay: How to find all Layouts with the specific JournalArticle in AssetPublisher portlets?
In almost in every wiki simple things are explained. I'm stuck in yii's CDbcriteria compare issue.
Only the exact "equal to" match is explained
for:
select * from users where status ='active'
This comparison is explained:
$criteria->compare('status','active');
But I can't find an example script which describes it with an operator based search. Like not equal to for the following query:
select * from users where status !='active'
How can I do this?
try some thing like this
$criteria->condition = " status<>'active'";
$criteria->compare('status',$this->status,true);
$criteria->addNotInCondition('status', array('active'));
if count(array('active')) === 1 sql will status != 'active', else status NOT IN ('active', 'smth else')
Try
$criteria->addCondition("NOT status = 'active'");
I had the below 3 conditions and it works like a charm:
$criteria->condition='employee_id<>:employee_id AND vehicle_id=:vehicle_id AND checked_in_on IS NULL';
$criteria->params=array(':employee_id'=>Yii::app()->session['activity']->employee_id,':vehicle_id'=>$model->id);
$checkedOutVehicleBySomeoneElse = Activity::model()->find($criteria);