简体   繁体   中英

How to convert SQL query to MongoDB

SELECT s_name FROM supplier 
WHERE s_suppkey = ALL
(SELECT s_suppkey FROM supplier
WHERE s_nationkey > 50 AND s_acctbal= 9658.99 )

I don't know how to do this part

WHERE s_suppkey = ALL
    (SELECT s_suppkey FROM supplier
    WHERE s_nationkey > 50 AND s_acctbal= 9658.99 )
db.supplier.find( {}, { $and : [  {  s_nationkey : { '$gt' : 50 } }, { s_acctbal : 9658.99 } ] } ,{s_suppkey:1} )

But does not return suppliers name!

You SQL looks a bit strange. For Mongo try this one:

db.supplier.find({ s_nationkey: { '$gt': 50 }, s_acctbal: 9658.99 }, {s_name :1} )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM