2016-10-28 9 views
0

列名に空白を持つJSONを照会するために私のデータセットは、次の形式は次のとおりです。Apacheのドリルが

{ 
    "business_id":"5UmKMjUEUNdYWqANhGckJw", 
    "full_address":"4734 Lebanon Church Rd\nDravosburg, PA 15034", 
    "hours":{ 
     "Friday":{ 
     "close":"21:00", 
     "open":"11:00" 
     }, 
     "Tuesday":{ 
     "close":"21:00", 
     "open":"11:00" 
     }, 
     "Thursday":{ 
     "close":"21:00", 
     "open":"11:00" 
     }, 
     "Wednesday":{ 
     "close":"21:00", 
     "open":"11:00" 
     }, 
     "Monday":{ 
     "close":"21:00", 
     "open":"11:00" 
     } 
    }, 
    "open":true, 
    "categories":[ 
     "Fast Food", 
     "Restaurants" 
    ], 
    "city":"Dravosburg", 
    "review_count":4, 
    "name":"Mr Hoagie", 
    "neighborhoods":[ 

    ], 
    "longitude":-79.9007057, 
    "state":"PA", 
    "stars":4.5, 
    "latitude":40.3543266, 
    "attributes":{ 
     "Take-out":true, 
     "Drive-Thru":false, 
     "Good For":{ 
     "dessert":false, 
     "latenight":false, 
     "lunch":false, 
     "dinner":false, 
     "brunch":false, 
     "breakfast":false 
     }, 
     "Caters":false, 
     "Noise Level":"average", 
     "Takes Reservations":false, 
     "Delivery":false, 
     "Ambience":{ 
     "romantic":false, 
     "intimate":false, 
     "classy":false, 
     "hipster":false, 
     "divey":false, 
     "touristy":false, 
     "trendy":false, 
     "upscale":false, 
     "casual":false 
     }, 
     "Parking":{ 
     "garage":false, 
     "street":false, 
     "validated":false, 
     "lot":false, 
     "valet":false 
     }, 
     "Has TV":false, 
     "Outdoor Seating":false, 
     "Attire":"casual", 
     "Alcohol":"none", 
     "Waiter Service":false, 
     "Accepts Credit Cards":true, 
     "Good for Kids":true, 
     "Good For Groups":true, 
     "Price Range":1 
    }, 
    "type":"business" 
} 

私は、データセットの属性を照会します。しかし、属性名の多くにはスペースが含まれています。スペースで属性名をどのように参照していますか?例 - 私はベガスのレストランの平均「価格帯」を探したい。

select avg(`t.attributes.Price Range`) from `mongo.274_BI`.`yelp_dataset`t where t.city = 'Las Vegas'; 

nullを返します。価格とレンジの間にスペースがあるために問題があります。私は問題なしで 'Parking'フィールドに質問しました。どうすればこの問題を解決できますか?クエリ以下

答えて

0

使用:

select avg(t.attributes.`Price Range`) from `mongo.274_BI`.`yelp_dataset`t where t.city = 'Las Vegas'; 

また、あなたはint型やdoubleとしてCASTattributes.Price Rangeに必要な場合があります。

例:助けて幸せ

select avg(cast(t.attributes.`Price Range` as double)) from `mongo.274_BI`.`yelp_dataset`t where t.city = 'Las Vegas'; 
+0

@RJP ... :) –

関連する問題