wc1
id name
1 南昌
2 武汉
3 北平
wc2
id name
1 广州
2 成都
myGo,viaF表示wc1下的所有城市均可用。
id startF viaF price
1 上海 wc1 12
2 上海 wc2 14
3 上海 南昌 8
查询时,可以得到这样吗?1 上海 南昌 12
2 上海 武汉 12
3 上海 北平 12
4 上海 广州 14
5 上海 成都 14
6 上海 南昌 8
是我的表设计有问题,还是一条语句不能实现。
id name
1 南昌
2 武汉
3 北平
wc2
id name
1 广州
2 成都
myGo,viaF表示wc1下的所有城市均可用。
id startF viaF price
1 上海 wc1 12
2 上海 wc2 14
3 上海 南昌 8
查询时,可以得到这样吗?1 上海 南昌 12
2 上海 武汉 12
3 上海 北平 12
4 上海 广州 14
5 上海 成都 14
6 上海 南昌 8
是我的表设计有问题,还是一条语句不能实现。
SELECT a.id,a.startF,b.name,a.price from myGo a ,wc1 b where a.viaF='wc1'
union all
SELECT a.id,a.startF,b.name,a.price from myGo a ,wc2 b where a.viaF='wc2'
union all
select a.* from myGo a where a.viaF not in('wc2','wc1')
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;这两条语句的结果分别是‘铜’和‘石’ 我这么样能把他们拼起来呢
from myGo a left join (
select 'wc1' as viaF, name from wc1
union all
select 'wc2' as viaF, name from wc2
) b on a.viaF=b.viaF
coalesce()解释:返回参数中的第一个非空表达式(从左向右);
显示第一个不是NULL的值。
多个参数也一样。mysql> select coalesce(1,2,3,4) ;
+-------------------+
| coalesce(1,2,3,4) |
+-------------------+
| 1 |
+-------------------+
1 row in set (0.00 sec)mysql> select coalesce(null,2,3,4) ;
+----------------------+
| coalesce(null,2,3,4) |
+----------------------+
| 2 |
+----------------------+
1 row in set (0.00 sec)mysql> select coalesce(null,null,3,4) ;
+-------------------------+
| coalesce(null,null,3,4) |
+-------------------------+
| 3 |
+-------------------------+
1 row in set (0.00 sec)