发布网友 发布时间:2022-04-22 20:42
共3个回答
热心网友 时间:2022-04-09 00:45
只能查出对应的 面积(area),株数(qty),产值(price) 值,表头是需要自己去弄,真对
数据如下:南厂,苗木1,花灌木,10,10,10
北厂,苗木2,花卉,10,10,10,
其它,苗木3,针叶松,10,10,10
这份数据,脚本如下
select sum(tt.南厂area1),sum(tt.南厂qty1),sum(tt.南厂price1),
sum(tt.北厂area2),sum(tt.北厂qty2),sum(tt.北厂price2),
sum(tt.其它area2),sum(tt.其它qty2),sum(tt.其它price2)
from (
select t.area as 南厂area1 ,t.qty as 南厂qty1,t.price 南厂price1,0 as 北厂area2,0 as 北厂qty2,0 as 北厂price2,
,0 as 其它area3,0 as 其它qty3,0 as 其它price3
from table_name t
where t.filed = '南厂' and t.name = '苗木1' and t.'type' = '花灌木'
union all
select 0 as 北厂area1,0 as 北厂qty1,0 as 北厂price1,t.area as 北厂area2 ,t.qty as 北厂qty2,t.price 北厂price2,
0 as 北厂area3,0 as 北厂qty3,0 as 北厂price3
from table_name t
where t.filed = '北厂' and t.name = '苗木2' and t.'type' = '花卉'
union all
select 0 as 北厂area1,0 as 北厂qty1,0 as 北厂price1,0 as 北厂area2,0 as 北厂qty2,0 as 北厂price2,
t.area as 北厂area3 ,t.qty as 北厂qty3,t.price 北厂price3
from table_name t
where t.filed = '其它' and t.name = '苗木3' and t.'type' = '花针叶松'
) tt
热心网友 时间:2022-04-09 02:03
增加一列场区aID,树木类型Ttype,表名Tree。
select x.ttype,x.area,x.qty,x.price,y.ttype,y.area,y.qty,y.price,
z.ttype,z.area,z.qty,z.price,w.ttype,w.area,w.qty,w.price
from TREE x,TREE y,TREE z,TREE w
where x.aid=y.aid and y.aid=z.aid and z.aid=w.aid and
x.ttype='针叶树' and y.ttype='阔叶树' and z.ttype='花灌木' and w.ttype='花卉';
表格和标题你自己用html里面的table画,数据可以用上面的句子获得就可以了(去掉树木名字)。
热心网友 时间:2022-04-09 03:38
使用如下语句进行分组,如果需要增加查询条件,可以再group by前增加where条件。
select type, max(area), max(qty), max(price) from table group by type;
不知道是不是你想要的效果,试试看吧。如果要根据类型求和,可以讲max换成sum