从 2 个表中提取数据

从 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.