select *
from (select a.drugname, a.drugform, a.drugspec, a.type flag, max(a.maxzjprice) maxprice, min(a.minzjprice) minprice from REP_YEAR_DRUG_ZJJ a group by a.drugname, a.drugform, a.drugspec, a.type)pivot(max(maxprice) d, max(minprice) g for flag in(1, 2))
这是按分类把列转行;超过两个以上的转列要给别名,不然会报错