从 2 个表中提取数据 [英] Extracting data from 2 tables
本文介绍了从 2 个表中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两张桌子
table1
eventcode mobile points name
-------------
CAMTRIP 82074626 10 SS
TARANAKI 91262063 30 JL
CAMTRIP 91262063 10 JL
和table2
passcode serial remark
----------
TARANAKI 1 NZ
CAMTRIP 2 Cameroon
我想要一个输出
Cameroon
NAME Points
----------
SS 10
JL 10
NZ
----------
JL 30
我正在努力
SELECT ( b.name ) name,
( b.points ) point,
( b.eventcode ) ecode,
( c.remark ) rem
FROM table1 b,
table2 c
WHERE c.passcode = b.eventcode
GROUP BY b.eventcode
我没有得到想要的结果.怎么了?
I don't get the desired result. what is wrong?
推荐答案
所以我猜你需要的实际结果是:
So I guess the actual result you need is:
Remark Name Points
----------------------
Cameroon SS 10
Cameroon JL 10
NZ JL 30
制作喀麦隆和新西兰组标题应在客户端完成.查询将是:
Making Cameroon and NZ group headers should be done in the client. The query for that would be:
SELECT t2.Remark, t1.Name, t1.Points
FROM table2 t2
INNER JOIN table1 t1 ON t2.passcode = t1.eventcode
只需在共享字段上JOIN
,然后在每个表中SELECT
任何你想要的字段.
Just JOIN
on the shared field, then SELECT
whatever fields you want from each table.
这篇关于从 2 个表中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文