首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

请问一个sql语句的有关问题

2012-03-06 
请教一个sql语句的问题select b.dicname as 样品类别from kcwms.enoutlist as a,kcwms.dictname as bwhe

请教一个sql语句的问题
select b.dicname as '样品类别'
from kcwms.enoutlist as a,kcwms.dictname as b
where b.dicid=a.sampletype and b.dictype='SAMPLE';

select b.dicname as '物品状态'
from kcwms.enoutlist as a,kcwms.dictname as b
where b.dicid=a.sampletype and b.dictype='STATE';
这两个sql语句合起来怎么写?
在线等。

[解决办法]
LZ是要分组查询吗? 
直接用group by dictype就行了 

select b.dicname from kcwms.enoutlist as a,kcwms.dictname as b
where b.dicid=a.sampletype 
group by b.dictype


[解决办法]
b.dicname 的别名有两个:'样品类别'和'物品状态'
要合起来的话,有难度……


如果两个别名一样的话就容易了:

SQL code
select b.dicname as '样品类别'from kcwms.enoutlist as a,kcwms.dictname as bwhere b.dicid=a.sampletype and b.dictype in ('SAMPLE','STATE');
[解决办法]
LZ 需要的结果是几列? 

如果是两列 做不到你需要的结果 列名不可能变化 


[解决办法]
select case when b.dictype='SAMPLE' then b.dicname else '' end as '样品类别'
,case when b.and b.dictype='STATE' then b.dicname else '' end as 物品状态'
from kcwms.enoutlist as a,kcwms.dictname as b
where b.dicid=a.sampletype ;

这样的话就产生了两个列 !楼主参照
[解决办法]
探讨
select case when b.dictype='SAMPLE' then b.dicname else '' end as '样品类别'
,case when b.and b.dictype='STATE' then b.dicname else '' end as 物品状态'
from kcwms.enoutlist as a,kcwms.dictname as b
where……

[解决办法]
SQL code
select '' as '物品状态',b.dicname as '样品类别'from kcwms.enoutlist as a,kcwms.dictname as bwhere b.dicid=a.sampletype and b.dictype='SAMPLE';union allselect b.dicname as '物品状态','' as '样品类别'from kcwms.enoutlist as a,kcwms.dictname as bwhere b.dicid=a.sampletype and b.dictype='STATE';是不是这个意思?when case 也可以实现 

热点排行