我有两个两张桌子:
表#1:列
Producer ConsumerKey time resourcepath Day
------------------------------------------------------------------
test 7890 2018-09-25 09:44 /12345 23
dev 5678 2018-09-25 09:10 /abcv 26
表#2:列
ConsumerName ConsumerKey Day
-----------------------------------
admin 7890 23
dummy 5678 26
我需要以某种方式查询表,以便在特定日期从表1中获得不同的值,并从表2中获得相应的消费者名称
所以最终结果应该像这样:
Producer ConsumerKey time resourcepath ConsumerName Day
-------------------------------------------------------------------------------
test 7890 2018-09-25 09:44 /12345 admin 23
dev 5678 2018-09-25 09:10 /abcv dummy 26
有什么办法可以做到这一点。任何帮助请
谢谢
答案 0 :(得分:0)
基本联接应该起作用。
SELECT t1.producer,
t1.consumerkey,
t1.time,
t1.resourcepath,
t2.consumername,
t1.day
FROM table1 t1
INNER JOIN table2 t2
ON t2.consumerkey = t1.consumerkey
AND t2.day = t1.day;
答案 1 :(得分:0)
SELECT DISTINCT table1.Producer, table1.ConsumerKey, table1.Time, table1.resourcepath, table1.day, table2.ConsumerName
FROM table1, table2
WHERE table1.ConsumerKey = table2.ConsumerKey
AND table1.time = "<ENTER YOUR TIME HERE>"
这样可以很好地获取以下详细信息。