I have an OrientDB table named CalculationFunctionGroup, in which I have a field named functions.
This field has JSON content like this:
[{"#type":"d","#version":0,"#class":"CalculationFunction","name":"AR_0015_0280","code":"//AR_0015_0280 OTTIMIZZATA / FORMATTATA\nvar worka01 = anagPay(\"AR_0015_0280\", -1);\nreturn worka01;","language":"Javascript"}]
I want to extract rows satisfying a LIKE condition on the code element of the JSON.
I've tried this query:
SELECT FROM CalculationFunctionGroup
WHERE functions.code LIKE '%OTTIMIZZATA%'
But the number of extracted rows is ZERO!
Try this:
select expand(distinct(rid))
from (select #rid,functions.code
from CalculationFunctionGroup unwind functions)
where functions like "%OTTIMIZZATA%"
Related
I want to retrieve all rows from a table in MySQL table where there is a JSON column called items with content like this:
[{"code":"MH005","qte":1,"totalpriceItem":"28.00"},{"code":"MH027","qte":1,"totalpriceItem":"28.00"}]
[{"code":"MH027","qte":1,"totalpriceItem":"30.00"}]
[{"code":"MH024","qte":1,"totalpriceItem":"28.00"},{"code":"MH028","qte":1,"totalpriceItem":"28.00"},{"code":"MH027","qte":1,"totalpriceItem":"28.00"}]
[{"code":"MH028","qte":1,"totalpriceItem":"30.00"}]
Now i want to be able to select all the row where the key code has the value MH027.
I've tried this but without success:
SELECT *
FROM `transactions`
WHERE JSON_CONTAINS(`item`, 'MH027', '$[*].code')
Any help is much appreciated.
If I understand correctly you need to use JSON_CONTAINS as follows:
SELECT *
FROM transactions
WHERE JSON_CONTAINS(item, '{"code": "MH027"}', '$')
The second parameter must be valid JSON. You could use JSON_OBJECT('code', 'MH028') if the value is dynamic or could contain special characters.
I am trying to query exact number in array inside text field in sql
so for example
SELECT tbl_campaigns.s_id,a_list_fk_i_id_tbl_affiliates
FROM tbl_campaigns
WHERE a_list_fk_i_id_tbl_affiliates LIKE '%1%'
can return
[3,8,7,11]
which is not good because i would like to get the arrays that contain 1
You could use JSON functions:
SELECT s_id,a_list_fk_i_id_tbl_affiliates
FROM tbl_campaigns
WHERE JSON_CONTAINS(a_list_fk_i_id_tbl_affiliates, 1)
Using KNIME, I would like to analyze data in a specific subset of columns in my database
but without using limiting SQL queries such as
Select *
From table
Where name like 'PAIN%'
Is there a way to do this in KNIME?
Try to find specific value within the column of choice by using:
Select distinct(column_name) from table;
You can pick from the expected result to filter your data
Select * from table column_name like 'result_one';
Assuming the column_name data type is in character.
To filer columns use the "Column Filter" node. You can filter the columns specifically, by RegEx on the column name or by column type (int, double, etc.) To filter rows based on content, use the "Row Filter" node, and select column to test and "filter based on collection elements" using pattern matching. This can also use RegEx. For mulitple columns use multiple nodes.
the knime did not support like for now, so I used the mysql locate or FIND_IN_SET function
SELECT id FROM address where LOCATE($street_Arr[0]$,street) > 0
SELECT id FROM address where FIND_IN_SET($street_Arr[0]$,street) > 0
however in the same situation u might be able to use knime joins much faster.
I have a column in my table name as URL and it contains Multiple value like "https://www.google.com/#q=how+to+make+a+android+app"
and
http://www.bing.com/search?q=how+to+make+a+android+app&go=&qs=n&form=QBLH&pq=how+to+make+a+android+app&sc=8-15&sp=-1&sk=
I want to get data separately in output like
website = https://www.google.com
Keyword = how to make a android app.
Any Idea Plz, How can i get this in MySql.
you can use substr() function in php to cut string. In your case, you can get the characters up to the end of 'https://www.google.com'.
read more at http://ro1.php.net/substr
in case you want to do it directly in your query, you can use substr() as well. Sql syntax goes like this:
SELECT SUBSTR(column, start_position, desired_length) FROM table_name
*SELECT SUBSTR(column_name, 1, 20) FROM table_name;*
I'm trying to get around pulling all the data from a table, and cycling through it with php. Here's my current Query:
SELECT
*
FROM
ExampleTable
WHERE
StringContains LIKE "%lkjlkjsomeuser#example.comjkjhkjhkjhkjhk,mniu,mk,mkjh%"
ExampleTable.StringContains has values that look like 'someuser#example.com', 'someuser2#example.com', etc.
This doesn't match because LIKE only finds sub strings of the column value, not the other way around. Any ideas on commands to find rows where the table value is a substring of the passed string?
SELECT
*
FROM
ExampleTable
WHERE
'lkjlkjsomeuser#example.comjkjhkjhkjhkjhk,mniu,mk,mkjh' LIKE
CONCAT('%', StringContains, '%')
Try this:
SELECT *
FROM ExampleTable
WHERE "lkjlkjsomeuser#example.comjkjhkjhkjhkjhk,mniu,mk,mkjh" LIKE
CONCAT("%",StringContains,"%")
The key is to recognize that the column variable just represents a string, and the LIKE statement is always comparing two strings in the form
"stringA" LIKE '%stringB%'
Usually people use it to search for a "part" of a string contained in the "whole" database field string, but you can easily switch them. The only extra tool you need is the CONCAT statement, since you want the database field to be the part instead of the whole. The CONCAT statement builds a string with the %'s around the database field string, and the string form of the argument is now equivalent to
"stringB" LIKE "%stringA%"
Just make the LIKE in the opposit order. Since you have to add those % you'll have to concatenate the field first:
SELECT *
FROM ExampleTable
WHERE "lkjlkjsomeuser#example.comjkjhkjhkjhkjhk,mniu,mk,mkjh" LIKE CONCAT('%', StringContains, '%');