我有下表
表:次
timeid time
1 10
2 11
3 3
Run Code Online (Sandbox Code Playgroud)
表:计数
countId timeID numberCounts times
1 1 1 0
2 2 3 11
2 2 3 12
3 2 3 13
4 3 1 0
Run Code Online (Sandbox Code Playgroud)
我正在使用的查询
SELECT
t.time AS "Start Channel",
c.times AS Lapse
FROM Times t
JOIN Count c ON c.Time_ID=t.Time_ID;
Run Code Online (Sandbox Code Playgroud)
输出量
+---------------+----------+
| Start Time | lapse |
+---------------+----------+
| 10 | 0 |
| 11 | 11 |
| 11 | 12 |
| 11 | 13 |
| 3 | 0 |
+---------------+----------+
Run Code Online (Sandbox Code Playgroud)
愿望结果:
+---------------+
| TimeS |
+---------------+
| 10 |
| 11 |
| 12 |
| 13 |
| 3 |
+---------------+
Run Code Online (Sandbox Code Playgroud)
从所需结果看,您似乎想要:
SELECT GREATEST(t.time, c.times) AS `TimeS`
FROM Times AS t
JOIN Count AS c
ON c.Time_ID = t.Time_ID
;
Run Code Online (Sandbox Code Playgroud)
但是问题的标题听起来像是您想要的:
SELECT time AS `TimeS`
FROM Times
UNION
SELECT times
FROM Count
;
Run Code Online (Sandbox Code Playgroud)
(0由于Count.times有时也会在结果中包含a 0)。