SQL语句合并如何实现。
select a.Name from T_C_CONSUMELEVELS as a,T_C_CUSTOMERLEVELS as b where b.SumLevel between a.LowerLimit and a.UpperLimit and CustomerID=120914120222248 and CalcType=1;
+------+
| Name |
+------+
| 铜 |
+------+
1 row in set
select a.Name from T_C_CONSUMELEVELS as a, T_C_CUSTOMERLEVELS as b where b.CountLevel between a.LowerLimit and a.UpperLimit and b.CustomerID=120914120222248 and a.CalcType=2;
+------+
| Name |
+------+
| 泥 |
+------+
1 row in set
这两条语句的结果分别是‘铜’和‘石’ 我这么样能把他们拼起来呢 用一条sql语句我想得到“铜泥”这个词
------解决方案--------------------select replace(group_concat(name),'',',')
from
(
select a.Name from T_C_CONSUMELEVELS as a,T_C_CUSTOMERLEVELS as b where b.SumLevel between a.LowerLimit and a.UpperLimit and CustomerID=120914120222248 and CalcType=1
UNION ALL
select a.Name from T_C_CONSUMELEVELS as a, T_C_CUSTOMERLEVELS as b where b.CountLevel between a.LowerLimit and a.UpperLimit and b.CustomerID=120914120222248 and a.CalcType=2
)t
group by id
------解决方案--------------------select group_concat(a.Name SEPARATOR '') from T_C_CONSUMELEVELS as a,T_C_CUSTOMERLEVELS as b where b.SumLevel between a.LowerLimit and a.UpperLimit and CustomerID=120914120222248 and (CalcType=1 or CalcType=2) ;