我有2张桌子。 SHead& SLINE
SHEAD
id - title - origin - Status - datetime
SLINE
id - sid - datetime - body
我想从SHead中选择所有记录,其中origin = 4.我只想从SLine中记录第一行。
因此,如果我在SHead中有一行原点= 4和SLine中的两个相关行,我只想返回一行。这可能吗?
答案 0 :(得分:1)
这是一种典型的方式:
select h.*, l.*
from shead h join
sline l
on l.sid = h.id
where s.original = 4 and
l.datetime = (select min(l2.datetime) from sline l2 where l2.sid = l.sid);
答案 1 :(得分:0)
以下是使用SELECT sh.*,
s1.*
FROM SLine s1
JOIN (SELECT Min(datetime) min_dt,
sid
FROM SLine
GROUP BY sid) s2
ON s2.min_dt = s1.datetime
AND s2.sid = s1.sid
JOIN SHead sh
ON sh.id = s1.sid
$url = 'http://sweet-api.com/api';
$params = array('skip' => 0, 'top' => 5000);
$header = array('Content-Type' => 'application/json');
$header = addBasicAuth($header, getenv('USER'), getenv('PASS'));
$response = request("GET", $url, $header, $params);
print($response);