I have a table consists of 3 JSON fields and each of them has data in the format like [1,2,3,4]. I want to find the difference (the elements which are in one field that is not in another field) between any of the two JSON fields using MySQL query (by only using queries).
For example:
field 1 : [1,2,3,4]
field 2 : [1,4]
So the result should be like [2,3]
I am looking for a solution that can be implemented inside a trigger. Please comment if any more details required. Thanks.
Related
I have an Access Database with over 5 million rows and I can't seem to figure out how to filter it properly.
Each cell/row has data similar to the below:
3255128617[11666]21128351869
I am trying to filter the data based on the text within the [ brackets, so that only rows that have [11666] in the string are returned.
I have tried using the Like query with different wildcards but nothing seems to work.
Is there a simple way to filter my column so that only cells that contain [11166] anywhere in the string are returned?
Thanks in advance.
Use Like in the criteria:
WHERE [YourField] Like "*[[11666]]*"
I'm using the "phpsoda" library and trying to query the city of Seattle's permits dataset through the Socrata API (SODA). Data: https://data.seattle.gov/Permitting/Land-Use-Permits/ht3q-kdvx
They have several columns such as the ones I'm selecting below, but in the "AppliedDate" and "IssuedDatae" columns, there may or may not be data in that column.
So when I try to look at the array and arrange this into an HTML table, I'm getting some arrays (rows) that have fewer elements (columns) than other rows. This turns out to make it difficult to display since I don't know which columns are missing in the array (row).
I'm wondering if when I make the query, that those empty fields will look they seem in the visualized table on their site or when I export a CSV. Those columns in the query will return into the array element an empty string ("") instead so my rows and columns will come out all filled with values.
$soql->select("PermitNum", "AppliedDate", "IssuedDate", "Description", "OriginalAddress1")
->where("PermitClass = 'Multifamily' OR PermitClass = 'Commercial')
->limit(20);
$results = $ds->getDataset($soql);
Data would look something like...
print_r($results);
Array[0] -> [Description]=>"XXXXXXX", [PermitNum]=>"123456"
Array[1] -> [Description]=>"XXXXXXX", [PermitNum]=>"234567", [AppliedDate]=>"XX/XX/XXXX"
So the first row is missing the "AppliedDate" column just because it's not in the data.
Will I need to just go through this manually in the results array using a loop and checking column names and inserting an empty string if the loop doesn't find a column?
Following my own advice, I was able to just check for each row key if a specific key was missing (array_key_exists function), then I'd fill it in with "" if it returned false.
This seemed to work.
I have same problem. Socrata API will skip empty field or null value. Means, if field is null or empty, the result will not show field-name:'', instead, the result will just missing this, that cause your shorter row.
This is annoying bug, I have to fix it by my own. If I found it missing field, I will have to add field-name:'' to the result json, that will fix your shorter row problem. Make equal length row.
I have imported JSON data from Hive database. The structure looks like the attached. JSON data has been dumped to Hive without normalizing. Is it possible to parse the data?. For example, in the attached image, the mentionedlocations column has some places mentioned and I want them to be in separate rows.
You can use the Json.Document function to read the column as JSON.
I'd suggest creating a custom column with this formula:
Record.ToTable(Json.Document([mentionedlocations]))
and then expanding that column to get the multiple rows you want.
Putting these together:
= Table.ExpandTableColumn(
Table.AddColumn(PreviousStep, "Custom",
each Record.ToTable(Json.Document([mentionedlocations]))),
"Custom", {"Name"}, {"locations"})
This takes the PreviousStep in the query, adds a Custom column which converts the JSON text into a table and then expands the Name column in each of the tables in the Custom column and renames the column locations.
More easy peasy:
Right click on the column > Transform > JSON
Now use the button at the top right of the same column and Power BI is going to use the JSON element as the column name
I have table named post in which there is a column called visible_user_ids in which comma separated values are there. When I display the post by respective user then I used the FIND_IN_SET().
e.g. FIND_IN_SET('8','visible_user_ids') it shows the all the records from post table for user id 8 when visible_user_ids column contains comma separated user ids such as
3,5,8
8,5
8,1,12
etc.
but when visible_user_ids column contain only one value i.e. 8 then it does not display the post table record.
Please suggest a solution. Whether FIND_IN_SET() works for single value?
Instead of
FIND_IN_SET('8','visible_user_ids')
Try this
FIND_IN_SET('8',visible_user_ids)
I am using the 'concatenate related' module created by Allen Browne to concatenate rows into a single field. At first I had a lookup field at the table level and later realized this is not a good approach. So I deleted the lookup column and instead made a query for selecting values from the lookup table on my form and then store that value as a number in the table.
The module works when I concatenate the values but it is listing the number (id) whereas I would like the actual description (i.e. 1 = Red, 2 = Blue, etc.)
My SQL query code is as follows:
SELECT DISTINCT
tblCompany.JobID,
concatrelated("type","tblMonitor","JobID = " & [jobID]) AS Expr1
FROM tblCompany;
I would like "type" to display the description instead of the number. I know if I store my lookup value as text instead of number it will work. But for efficiency it seems the number should be stored in the table and then query for the description when you need it....or maybe text is fine??? I'm guessing I would need to add the lookup table to this query. I have tried but with no luck so far.
Create a query which joins tblMonitor with the table which holds the type description field. Then use that query with ConcatRelated.
ConcatRelated("type_descriptn","YourQuery","JobID = " & [jobID])