How to use multiple functions in having clause - oracle10g

I am having problem while using having value.
The query I write in having clause is:
sum(min(nvl(qty,0)))>0
I get error:
'group function nested too deeply'

Related

Exporting result to csv in the middle of a cypher query

I'm trying to export the results of a query to csv and still re-use the values from the query result as inputs for the second stage of the query.
I submit an initial query in my postgres database and pass the results to neo4j using apoc.load.jdbc. I've been trying to export the results for this postgres query using apoc.export.csv.query and then use values from the postgres query as search criteria for my cypher query.
This query works without any attempt to write to csv:
CALL apoc.load.jdbc('postgresql_url', 'SELECT paper_id FROM papers LIMIT 1') YIELD row
MATCH (n:paper)<-[r:REFERENCES]-(m:paper) WHERE n.paper_id = row.paper_id
RETURN n, m
Ideally, I'd like a query that does something likes this:
CALL apoc.load.jdbc('postgresql_url', 'SELECT paper_id FROM papers LIMIT 1') YIELD row
CALL apoc.export.csv.query('row', 'export/degree0.csv', {}) YIELD row
MATCH (n:paper)<-[r:REFERENCES]-(m:paper) WHERE n.paper_id = row.paper_id
RETURN n, m
This query returns and error that it row.paper_id is not defined.
I'm trying to get the results of the postgres query written to a csv and use data from that query result in the cypher query.
it is possible you are overriding the row variable.
you can try removing the 'YIELD row' from the export.csv in the second line.
if it doesn't work I would suggest removing also the match line and just Return *, so you can see exactly what the row variable contains.

How to Place a variable in pyspark groupby agg query

Hi I have query in which i want to place the variable data into the group by query
i Tried like this but it not working
dd2=(dd1.groupBy("hours").agg({'%s':'%s'})%(columnname1,input1))
In the columnname1 contain 'total' and input1 contain what kind of aggregation is required like mean or stddev.
i want this query to be dynamic.
Try this,
dd2=(dd1.groupBy("hours").agg({'{}'.format(columnname1):'{}'.format(input1)}))

MongoDB: min(), max() doesn't support embedded document

I have applied index on embedded document field which is of type date. Due to unpredictable behavior of MongoDB query with $lt & $gt operators I am trying to use min() max() functions of Cursor which force both lower & upper bounds on the index. But when I used it, it gave me error:
planner returned error: unable to find relevant index for max/min query"
Query looks like:
db.user.find().min({'record.date':ISODate("2014-12-01")}).max({'record.date':ISODate("2014-12-01")}).explain()
I have indexed the field 'record.date'. I even tried to force it with hint() but of no use. It showed me this error:
planner returned error: hint provided does not work with min query"
Somewhere on the Internet I saw on one of the forums that we can query with embedded fields in min(), max() functions. Field 'record' is an array of sub-documents. I have another field of type date in main document for which min(), max() worked fine (this field is indexed too). Can anyone guess why is this happening?
sample document:
user:
{name:'ad',dob: ISODate('yyyy-mm-dd'),createdAt: ISODate(),...,record:[
{date:ISODate:(),...
},...]}
Index was created as:
db.user.ensureIndex({'record.date':1})
Thanks.

mongoid distinct with matching

In mongodb you could use command like
db.sessions.distinct("Ip",{ 'Application': '123'})
which will return all unique ip for the selected application. How to do that via Mongoid?
I trying to pass 2 argument in distinct function but it fails with exception 'ArgumentError: wrong number of arguments (2 for 1)'
Distinct in Mongoid takes one argument -- the field you wish to filter distinct on. So in your case, you could chain a where clause w/a distinct like so:
YourModel.where(Application: '123').distinct(:Ip)
This would produce a collection of distinct YourModel's by field Ip where the field Application is equal to '123'.
Show you full distinct query, please.
I try follow syntax with users collection(3 documents with name Bob):
db.users.distinct("_id", {name: "Bob"})
And It's works:
[
ObjectId("5121792d499af102889f2576"),
ObjectId("5121792e499af102889f2577"),
ObjectId("5121792f499af102889f2578")
]
My MongoDB version is 2.2.0

MongoDB: How to execute a query to result of another query (nested queries)?

I need to apply a set of filters (queries) to a collection. By default, the MongoDB applies AND operator to all queries submitted to find function. Instead of whole AND I need to apply each query sequentially (one by one). That is, I need to run the first-query and get a set of documents, run the second-query to result of first-query, and so on.
Is this Possible?
db.list.find({..q1..}).find({..q2..}).find({..q3..});
Instead Of:
db.list.find({..q1..}, {..q2..}, {..q3..});
Why do I need this?
Bcoz, the second-query needs to apply an aggregate function to result of first-query, instead of applying the aggregate to whole collection.
Yes this is possible in MongoDB. You can write nested queries as per the requirement.Even in my application I created nested MongoDb queries.If you are familiar with SQL syntax then compare this with in of sql syntax:
select cname from table where cid in (select .....)
In the same way you can create nested MongoDB queries on different collections also.