iT邦幫忙

0

SQL 如何實現以下尋找

本人有一個查詢功能要去完成,但想不到如何實現比較好,希望各位能解答一下.
分別有二個表
表A
表內有ID,ITEM 1-6,開始日期,結束日期,B表ID
表B
表內有ID,ITEM 1-3
A表和B表ITEM1-3完全不同

現在我是做了以下SQL:
SELECT ITEM 1-3 FROM B WHERE ID IN (SELECT B表ID FROM A WHERE 結束日期>今天) ........
如何把子SQL 內A表的ITEM 1-6 都能同時尋找出來.

33489 iT邦新手 5 級 ‧ 2021-12-09 12:02:38 檢舉
已經做到,感謝下面二位解答
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

6
firecold
iT邦新手 1 級 ‧ 2021-12-08 14:33:18
最佳解答
select b.item1, b.item2, b.item3, 
a.item1 as aitem1, a.tiem2 as aitem2, a.tiem3 as aitem3,
a.tiem4 as aitem4, a.tiem5 as aitem5, a.tiem6 as aitem6
from `tableA` a, `tableB` b
where  a.end_at > 今天
and a.b_id = b.id

部份column name跟變數記得改掉

peter4405 iT邦新手 5 級 ‧ 2021-12-08 16:30:10 檢舉

最下面那個where 要改成and

firecold iT邦新手 1 級 ‧ 2021-12-08 18:33:47 檢舉

感謝提醒

1
peter4405
iT邦新手 5 級 ‧ 2021-12-08 16:29:30

select a.* , b.*
from tablea a , tableb b
where a.b_id= b.b_id
and a.結束日> current timestamp

我要發表回答

立即登入回答