我需要将SQL查询转换为LINQ,但不知道如何。 我有两个表:Bins和DataFromBins。 DataFromBins包含引用Bins.Id的BinId列 我的查询要做的是从DataFromBins中为每个BinId选择最新行,并从Bins中为这些BinId连接一些数据。
请帮助:(
SELECT BinId, Address, Lon, Lat, MaxFillLevel, Distance
FROM (
SELECT DataFromBins.*
FROM (
SELECT DataFromBins.BinId, MAX(DataFromBins.Date) AS Date
FROM DataFromBins
GROUP BY DataFromBins.BinId
) AS latest_records
INNER JOIN DataFromBins ON DataFromBins.BinId = latest_records.BinId
AND DataFromBins.Date = latest_records.Date
) AS most_recent
INNER JOIN Bins ON most_recent.BinId = Bins.Id
答案 0 :(得分:0)
我想您正在寻找下面的代码。诀窍是拆分您的子查询;)
假设 [{"responseId":"6c64c1b9-5505-43b4-8fd0-a7b40367547a-fd8ff490","queryResult":{"fulfillmentMessages":[{"platform":"FACEBOOK","text":{"text":["this is response text that works! Now click on one button below"]},"message":"text"},{"platform":"FACEBOOK","card":{"buttons":[{"text":"button1","postback":"https://www.example.com/one"},{"text":"button2","postback":"https://www.example.com/two"},{"text":"button3","postback":"https://www.exaple.com/t"}],"title":"Buttons!","subtitle":"","imageUri":""},"message":"card"}, ...
是您的上下文。
function callSendAPI(sender_psid, response) {
// Construct the message body
let request_body = {
"recipient": {
"id": sender_psid
},
"message": response
}
// Send the HTTP request to the Messenger Platform
request({
"uri": "https://graph.facebook.com/v3.2/me/messages",
"qs": { "access_token": process.env.PAGE_ACCESS_TOKEN },
"method": "POST",
"json": request_body
}, (err, res, body) => {
if (!err) {
console.log('message sent!')
} else {
console.error("Unable to send message:" + err);
}
});
}