我从两个表中选择了数据;
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的专家,所以我真的需要答案。 TQ
答案 0 :(得分: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;
答案 1 :(得分: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;