Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 days ago.
Improve this question
I have similar database in CosmosDB gremlin API and Cosmos DB SQL API.
I have a query in gremlin which Get details of all neighbors of id 100
g.V().has('id', '100').out().values('id','desc').
I get
[101,blanca
102,raj]
Now in SQL I similarly want to find out neighbours of id 100 So I wrote a query
SELECT *
FROM c
where c.id = "100"
and I am able to pull that record which has its relations
[
{
"id": "100",
"pk": "100",
"relationships": [
"parent|father|100|101",
"parent|mother|100|102",
]
}
]
It means it has two relation as father and mother with id 101 and 102.
So how do I write a query to pull that 101, 102(neighbours) using id 100 and write a nested query to pull that desc again?
I did try a lot of nested queries and nothing is working out
SELECT c1.id, c1.description
FROM c c1
WHERE c1.id IN (
SELECT value FROM UNNEST(
(SELECT c2.relationships
FROM c c2
WHERE c2.id = "100")[0].vertices
)
)
Related
In NodeJs with MS-SQL, I want to retrieve two three table data in the form of array of objects
Hello there my name is Shaziya, please help me out (โยดโ`โ)
Actually i have done NodeJs from YouTube,
I want learn NodeJS with MS-SQL, do you or any friends have such course for Advance understanding,
Like how to connect 4 5 tables and show data in array of objects format
How to make nested query or subquires like...
I mean if wanna do table match with two table product and order
Product ID with Order table by matching product ID
data {
productId : 1:
productName : "abc",
[{
orderId : 1
orderName : "xyz"
},
{
orderId : 2
orderName : "pqr"
}
]
}
At least i got some course or solution for that where i stuck
I have two kind of record mention below in my table staudentdetail of cosmosDb.In below example previousSchooldetail is nullable filed and it can be present for student or not.
sample record below :-
{
"empid": "1234",
"empname": "ram",
"schoolname": "high school ,bankur",
"class": "10",
"previousSchooldetail": {
"prevSchoolName": "1763440",
"YearLeft": "2001"
} --(Nullable)
}
{
"empid": "12345",
"empname": "shyam",
"schoolname": "high school",
"class": "10"
}
I am trying to access the above record from azure databricks using pyspark or scala code .But when we are building the dataframe reading it from cosmos db it does not bring previousSchooldetail detail in the data frame.But when we change the query including id for which the previousSchooldetail show in the data frame .
Case 1:-
val Query = "SELECT * FROM c "
Result when query fired directly
empid
empname
schoolname
class
Case2:-
val Query = "SELECT * FROM c where c.empid=1234"
Result when query fired with where clause.
empid
empname
school name
class
previousSchooldetail
prevSchoolName
YearLeft
Could you please tell me why i am not able to get previousSchooldetail in case 1 and how should i proceed.
As #Jayendran, mentioned in the comments, the first query will give you the previouschooldetail document wherever they are available. Else, the column would not be present.
You can have this column present for all the scenarios by using the IS_DEFINED function. Try tweaking your query as below:
SELECT c.empid,
c.empname,
IS_DEFINED(c.previousSchooldetail) ? c.previousSchooldetail : null
as previousSchooldetail,
c.schoolname,
c.class
FROM c
If you are looking to get the result as a flat structure, it can be tricky and would need to use two separate queries such as:
Query 1
SELECT c.empid,
c.empname,
c.schoolname,
c.class,
p.prevSchoolName,
p.YearLeft
FROM c JOIN c.previousSchooldetail p
Query 2
SELECT c.empid,
c.empname,
c.schoolname,
c.class,
null as prevSchoolName,
null as YearLeft
FROM c
WHERE not IS_DEFINED (c.previousSchooldetail) or
c.previousSchooldetail = null
Unfortunately, Cosmos DB does not support LEFT JOIN or UNION. Hence, I'm not sure if you can achieve this in a single query.
Alternatively, you can create a stored procedure to return the desired result.
This question already has answers here:
mongoDB distinct & where in same query?
(4 answers)
MongoDB select distinct and where
(2 answers)
Mongodb find() query : return only unique values (no duplicates) [duplicate]
(1 answer)
Closed 3 years ago.
I have a collection depdata in MongoDb. This contains below json data:
1st document:
{
"Type": "R1",
"Score": "20"
}
2nd document:
{
"Type": "R2",
"Score": 340"
}
I am using python and connected to the database. I have to get the values of the variable Score from all the documents in the collection depdata. For this I can do below:
val = depdata_collection.distinct('Score')
and this gives me the values of all the Score in the collection as list. But here I want to apply the condition where Type should only be R2. How can I write query for this and get the values only where Type is R2. Thanks
Use second argument in the distinct query
val = depdata_collection.distinct('Score', { "Type": "R2" })
Forgive me for asking something that is probably explained elsewhere, but I didnt found a simple and plain conversion/explanation of SQL model to Cassandra Model.
Lets say I've a use-case of designing a DB structure for employee details and records in a organization. In SQL(having years of experience), I could have modelled it using normalization techniques, but coming into the world of NoSQL, it would take me sometime to have hold over designing DB for NoSQL, hence I'm here (for better understanding).
Can someone transform this SQL model into a NoSQL(Cassandra) model, thereby giving a lot of newbies(like me) a simple and plain transformation of SQL to NoSQL migration.
Since SO works on a concept Try First and then ask, so Ive thought of a structure as well. Let me know if that works well.
Since data can be denormalized in Cassandra, I thought of this structure.
Emploee(ColumnFamily) = {
"01234"(EmployeeId) : {
"EmpName" : "Jack",
"mail" : "Jack#xyz.com",
"phone" : ["9999900000","8888888888"],
"DOB": 4/1/91,
"Contact":{ "Street" : XYZ2 , "City":ABC, "Pincode":PQR},
"UnitID":{ "UnitName" : XYZ , "UnitHead":ABC},
"RoleID":{ "Designation" : Manage , "Band":Something},
},
"01235"(EmploeeId) : {
"EmpName" : "Jackyyy",
"mail" : "Jackyyy#xyz.com",
"phone" : ["99565600000","88888846468"],
"DOB": 4/1/91,
"Contact":{ "Strreet" : XYZ2 , "City":ABC1, "Pincode":PQR},
"UnitID":{ "UnitName" : XYZ1 , "UnitHead":ABC1},
"RoleID":{ "Designation" : Faculty , "Band":Something},
},
and so on...
}
Projects(ColumnFamily) = {
"1213"(ProjectId) : {
"EmpID" : [01234,01235],
"StartDate" : 4/1/2001,
"EndDateDate": 4/1/2012,
"ClientName": Apple
"Description": "Something",
},
and so on...
}
Attentance Detail(ColumnFamily) = {
"1213"(DetailId) : {
"EmpID" : 01234,
"SwipeInTime" : Something,
"SwipeOutTime": Something,
"Status": Apple
},
and so on...
}
Firstly please let me know, if this structure is correct. If yes, how would I design queries for the following?
1) Select employee whose phone number = something;
2) Select employees who lives in 'XYZ' location;
3) Select employees whose age is > 40 years ;
4) Select employee whose Designation is a 'Manager' of Unit Name 'XYZ' ;
5) Select employees who work for over 1o hours a day;
6) Get names(not IDs) of all employees wh were working for client 'Apple';
Let me know If I can provide more clarity on the question!!!
Your structure is not correct because you won't be able to express any of your 6 queries :-(
The main rule of Cassandra modeling is: start from your queries and denormalize. In your case, you would have 6 tables employee_by_phone, employee_by_location, employee_by_age and so on.
http://www.datastax.com/dev/blog/basic-rules-of-cassandra-data-modeling
However if you have a lot of multi-criteria queries like these, Cassandra (Datastax Enterprise edition) has SolR extension which will let you express richer queries. In this case your model may be right.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
SQL : How can I use sub query in a query with group by section?
Some one help me please . SQL Server cant recognize t1.sen in subquery . Error message : The multi-part identifier "t1.sen" could not be bound.
select
t1.sen,
sum(t1.d_rooz)as d1,
sum(t1.d_shab)as d2,
sum(t1.d_rooz+t1.d_shab) as d_sum,
Round((sum((1000*(t1.d_rooz+t1.d_shab))/(9500-tc.c))),1) as SSS
from
tbl_talafat_dan t1, (
select sum(t2.t_shab+t2.t_rooz) as c
from tbl_talafat_dan t2
where FCode=81 AND DCode=1 AND t2.sen<=t1.sen
) as tc
where
FCode = 81
AND DCode = 1
group by
t1.sen
I think you have a syntax issue here after t1:
from
tbl_talafat_dan t1, (
select sum(t2.t_shab+t2.t_rooz) as c
from tbl_talafat_dan t2
where FCode=81 AND DCode=1 AND t2.sen<=t1.sen
) as tc
It's trying to figure out what's the table to select from. You need to use either t1 or tc and join after that appropriately. Hope this helps.