1

我从两个表中选择了数据;

mysql> select rq_grcode, mo_date from mg_log where rq_grcode like 'AM%' and mo_date like '2010-05%' group by rq_grcode order by rq_grcode asc;
+-----------+------------+
| rq_grcode | mo_date    |
+-----------+------------+
| AM0001    | 2010-05-20 |
| AM0029    | 2010-05-20 |
| AM0035    | 2010-05-20 |
+-----------+------------+
3 rows in set (0.00 sec)

mysql> select a.grcode, a.cpid, b.mo_date from mg_content a, mg_log b where a.grcode like 'AM%' and b.mo_date like '2010-05%' group by a.grcode order by a.grcode asc;
+--------+------+------------+
| grcode | cpid | mo_date    |
+--------+------+------------+
| AM0013 | CP02 | 2010-05-17 |
| AM0014 | CP02 | 2010-05-17 |
| AM0015 | CP02 | 2010-05-17 |
| AM0017 | CP02 | 2010-05-17 |
| AM0018 | CP02 | 2010-05-17 |
| AM0019 | CP02 | 2010-05-17 |
| AM0020 | CP02 | 2010-05-17 |
| AM0021 | CP02 | 2010-05-17 |
| AM0022 | CP02 | 2010-05-17 |
| AM0023 | CP02 | 2010-05-17 |
| AM0024 | CP02 | 2010-05-17 |
| AM0025 | CP02 | 2010-05-17 |
| AM0026 | CP02 | 2010-05-17 |
| AM0027 | CP02 | 2010-05-17 |
| AM0028 | CP02 | 2010-05-17 |
| AM0029 | CP02 | 2010-05-17 |
| AM0030 | CP02 | 2010-05-17 |
| AM0031 | CP02 | 2010-05-17 |
| AM0032 | CP02 | 2010-05-17 |
| AM0033 | CP02 | 2010-05-17 |
| AM0034 | CP02 | 2010-05-17 |
| AM0035 | CP02 | 2010-05-17 |
| AM0036 | CP02 | 2010-05-17 |
| AM0037 | CP02 | 2010-05-17 |
| AM0038 | CP02 | 2010-05-17 |
| AM0039 | CP02 | 2010-05-17 |
| AM0040 | CP02 | 2010-05-17 |
| AM0041 | CP02 | 2010-05-17 |
| AM0042 | CP02 | 2010-05-17 |
| AM0043 | CP02 | 2010-05-17 |
| AM0044 | CP02 | 2010-05-17 |
| AM0045 | CP02 | 2010-05-17 |
| AM0046 | CP02 | 2010-05-17 |
| AM0047 | CP02 | 2010-05-17 |
| AM0048 | CP02 | 2010-05-17 |
+--------+------+------------+
35 rows in set (0.01 sec)

如何显示来自 grcode 和 rq_grcode 列的所有数据?我不是mysql专家,所以我真的需要答案。时间

4

2 回答 2

0
select a.*, b.* from mg_content a, mg_log b 
where a.grcode like 'AM%' and b.mo_date like '2010-05%' 
group by a.grcode 
order by a.grcode asc;
于 2013-10-10T08:52:11.030 回答
0

这是你在找什么?

select rq_grcode, null as cpid, mo_date from mg_log where rq_grcode like 'AM%' and mo_date like '2010-05%' group by rq_grcode order by rq_grcode asc
union
select a.grcode, a.cpid, b.mo_date from mg_content a, mg_log b where a.grcode like 'AM%' and b.mo_date like '2010-05%' group by a.grcode order by a.grcode asc;
于 2013-10-10T08:54:25.817 回答