While using BigQuery's Console, we were instructed to input some data.
The following example was used for guidance
SELECT * FROM `bigquery-public-data.new_york_citibike.citibike_trips`
Afterward, I ran the query as instructed and removed the LIMIT clause.
The [JSON] results produced this information ...
[{
"tripduration": "2083",
"starttime": "2016-04-18T13:02:24",
"stoptime": "2016-04-18T13:37:08",
"start_station_id": "417",
"start_station_name": "Barclay St \\u0026 Church St",
"start_station_latitude": "40.71291224",
"start_station_longitude": "-74.01020234",
"end_station_id": "309",
"end_station_name": "Murray St \\u0026 West St",
"end_station_latitude": "40.7149787",
"end_station_longitude": "-74.013012",
"bikeid": "23641",
"usertype": "Subscriber",
"birth_year": "1945",
"gender": "male",
"customer_plan": ""
},]
Some of the results were deleted (TRIM).
I attempted to locate the longest ride on the citibikes and the shortest ride as well. (In terms of distance).
I didn't calibrate the information correctly. Therefore, I didn't receive any response for this calculation.
[JSON] is a query result-based language, will it create the same response each time it's used for public datasets?
Related
This is my MYSQL query:
SELECT country, vaccines, MAX(people_fully_vaccinated_per_hundred) as vaccinated_precentage
FROM country_vaccinations
WHERE people_fully_vaccinated_per_hundred > 60
GROUP BY country, vaccines
ORDER BY MAX(people_fully_vaccinated_per_hundred) DESC;
It basically lists all countries that have fully vaccinated more than 60% of its people, and the types of vaccine offered by that country.
I am trying to do the same on MongoDB:
db.country_vaccinations.aggregate([
{$project: {_id:0,
country: 1,
vaccines: 1,
people_fully_vaccinated_per_hundred: 1},
}
{$match: {"people_fully_vaccinated_per_hundred":{$gt:60}}}
])
However, I am not sure why it returns "No Records Found" when i add in the $match to retrieve rows that have "people_fully_vaccinated_per_hundred">60%.
Can someone advise me on what is my mistake? I would really appreciate it, as I am new to noSQL and am not sure why.
I am not sure it does the same, test it before using it, and if doesn't work, give us if you can some sample data and the expected output so we can test it.
country_vaccinations.aggregate(
[{"$match": {"people_fully_vaccinated_per_hundred": {"$gt": 60}}},
{"$group":
{"_id": {"country": "$country", "vaccines": "$vaccines"},
"vaccinated_precentage": {"$max": "$people_fully_vaccinated_per_hundred"}}},
{"$sort": {"vaccinated_precentage": -1}},
{"$project":
{"_id": 0,
"country": "$_id.country",
"vaccines": "$_id.vaccines",
"vaccinated_precentage": 1}}])
An SQL table schema,
time, country, activer_users
If I just want to show the total number of active users over time, Below simple slect wil do that
SELECT time, sum(active_users) as activer_users GROUP BY time ORDER BY time
returned data will be like,
[{
"time": 1585878969,
"active_users": 2300
},....]
If I want active_users over time by country, then
SELECT time, country, sum(active_users) as activer_users GROUP BY time ORDER BY time, country
returned data will be like,
[{
"time": 1585878969,
"active_users": 1300,
"country": "India"
}, {
"time": 1585878969,
"active_users": 1000,
"country": "China"
}....]
I want data in the below format,
[{
"time": 1585878969,
"India": 1300,
"China": "1000"
}....]
Is this possible, to create dynamic columns from the value of a field and its value based on another field..
if suchthing is possible, what should be the query for that
Other helpful users may correct me, but I think is not possible altering MySQL responses like this. MySQL always responds in a COLUMN-VALUE way, so you would have to create a column e.g. "China" and store this data in there to get a native response like this.
For a newly created Dynamics 365 Opportunity entity why is the processid GUID all zeros, should it not by the GUID for the qualify stage? Furthermore, why is the only other processid I see when closing the opportunity the 3e8ebee6-a2bc-4451-9c5f-b146b085413a. I expected to see this GUID in the qualify stage, but instead see all zeros. In this case once the opportunity is closed should it not show the GUID for close 919e14d1-6489-4852-abd0-a63a6ecaac5d? The stepname also appears to not update.
https://org.api.crm.dynamics.com/api/data/v9.0/opportunities?$expand=stageid_processstage&$select=name,processid, stageid, stageid_processstage,salesstage,stepname
{
"#odata.context": "https://org.api.crm.dynamics.com/api/data/v9.0/$metadata#opportunities(name,processid,stageid,stageid_processstage,salesstage,stepname)",
"value": [
{
"#odata.etag": "W/\"6752584\"",
"name": "Test",
"processid": "3e8ebee6-a2bc-4451-9c5f-b146b085413a",
"stageid": null,
"salesstage": null,
"stepname": "1-Qualify",
"opportunityid": "b5763e98-dabe-e911-a81f-000d3a18280a",
"stageid_processstage": null
},
{
"#odata.etag": "W/\"6752626\"",
"name": "Test Again",
"processid": "00000000-0000-0000-0000-000000000000",
"stageid": null,
"salesstage": null,
"stepname": "1-Qualify",
"opportunityid": "725a36a4-dfbe-e911-a81f-000d3a18280a",
"stageid_processstage": null
}
]
}
Turns out this is a deprecation issue.
This is because Microsoft deprecated processid, process stage name and few more info directly from main entity ( in your case opportunity) to new businesses process flow entity and its record.
Do one thing go to advanced find and therein try to find entity ( name shall be your process name, for ex: oppportunity process or something)
When you retrieve those records you will see for each opportunity record there is one record in this business process entity and there you find more details about your business process.
Here in docs you find more info about it
https://learn.microsoft.com/en-us/dynamics365/customer-engagement/customize/business-process-flows-overview
And this is more relevant for you
https://www.google.com/amp/s/www.inogic.com/blog/2019/02/business-process-flow-stage-name-in-dynamics-365/amp/
I am trying to update the fields age and city of one json feed using:
select jsonb_set(d,'{0,age,city}',d || '{"age":30,"city":"los angeles"}')
from (
values ('{"name":"john", "age":26,"city":"new york city"}'::jsonb)
) t(d);
but what I get back is:
{"age": 26, "city": "new york city", "name": "john"}
instead of the expected:
{"age": 30, "city": "los angeles", "name": "john"}
that means none of the wanted fields have been updated.
I have already looked at:
postgres jsonb_set multiple keys update
and went through the relative documentation but I cannot get it right. Any help?
From the documentation:
All the items of the path parameter of jsonb_set as well as jsonb_insert except the last item must be present in the target.
The path given in the query does not meet the above condition. Actually, jsonb_set() does not work for objects at the root level, and the only way is to use the || operator:
select d || '{"age":30,"city":"los angeles"}'
from (
values ('{"name":"john", "age":26,"city":"new york city"}'::jsonb)
) t(d);
?column?
----------------------------------------------------
{"age": 30, "city": "los angeles", "name": "john"}
(1 row)
Maybe it would be logical that you could use an empty path
select jsonb_set(d, '{}', d || '{"age":30,"city":"los angeles"}')
Unfortunately, jsonb developers did not provide such a possibility.
I have created a new bucket, FooBar on my couchbase server.
I have a Json Document which is a List with some properties and it is in my couchbase bucket as follows:
[
{
"Venue": "Venue1",
"Country": "AU",
"Locale": "QLD"
},
{
"Venue": "Venue2",
"Country": "AU",
"Locale": "NSW"
},
{
"Venue": "Venue3",
"Country": "AU",
"Locale": "NSW"
}
]
How Do i get the couchbase query to return a List of Locations when using N1QL query.
For instance, SELECT * FROM FooBar WHERE Locale = 'QLD'
Please let me know of any indexes I would need to create as well. Additionally, how can i return only results where the object is of type Location, and not say another object which may have the 'Locale' Property.
Chud
PS - I have also created some indexes, however I would like an unbiased answer on how to achieve this.
Typically you would store these as separate documents, rather than in a single document as an array of objects, which is how the data is currently shown.
Since you can mix document structures, the usual pattern to distinguish them is to have something like a 'type' field. ('type' is in no way special, just the most common choice.)
So your example would look like:
{
"Venue": "Venue1",
"Country": "AU",
"Locale": "QLD",
"type": "location"
}
...
{
"Venue": "Venue3",
"Country": "AU",
"Locale": "NSW",
"type": "location"
}
where each JSON object would be a separate document with a unique document ID. (If you have some predefined data you want to load, look at cbimport for how to add it to your database. There are a few different formats for doing it. You can also have it generate document IDs for you.)
Then, what #vsr wrote is correct. You'd create an index on the Locale field. That will be optimal for the query you want. Note you could create an index on every document with CREATE INDEX ix1 ON FooBar(Locale); too. In this simple case it doesn't really make a difference. Read about the query Explain feature of the admin console to for help using that to understand optimizing queries.
Finally, the query #vsr wrote is also correct:
SELECT * FROM FooBar WHERE type = "Location" AND Locale = "QLD";
CREATE INDEX ix1 ON FooBar(Locale);
https://dzone.com/articles/designing-index-for-query-in-couchbase-n1ql
CREATE INDEX ix1 ON FooBar(Locale) WHERE type = "Location";
SELECT * FROM FooBar WHERE type = "Location" AND Locale = "QLD";
If it is array and filed name is list
CREATE INDEX ix1 ON FooBar(DISTINCT ARRAY v.Locale FOR v IN list END) WHERE type = "Location";
SELECT * FROM FooBar WHERE type = "Location" AND ANY v IN list SATISFIES v.Locale = "QLD" END;