交叉表行列转换
2016-12-15 14:27
120 查看
You can simulate a CROSSTAB by the following method:-
Use IF function to select the key value of the sub table as in:
SELECT
SUM(IF(beta_idx=1, beta_value,0)) as beta1_value,
SUM(IF(beta_idx=2, beta_value,0)) as beta2_value,
SUM(IF(beta_idx=3, beta_value,0)) as beta3_value
FROM alpha JOIN beta WHERE alpha_id = beta_alpha_id;
where alpha table has the form alpha_id, alpha_blah, alpha_blah_blah
and beta table has the form beta_alpha_id, beta_other stuff,
beta_idx, beta_value
This will create 3 columns with totals of beta values according to their idx field
Use IF function to select the key value of the sub table as in:
SELECT
SUM(IF(beta_idx=1, beta_value,0)) as beta1_value,
SUM(IF(beta_idx=2, beta_value,0)) as beta2_value,
SUM(IF(beta_idx=3, beta_value,0)) as beta3_value
FROM alpha JOIN beta WHERE alpha_id = beta_alpha_id;
where alpha table has the form alpha_id, alpha_blah, alpha_blah_blah
and beta table has the form beta_alpha_id, beta_other stuff,
beta_idx, beta_value
This will create 3 columns with totals of beta values according to their idx field
相关文章推荐
- 行列转换 交叉表
- mysql 行列动态转换(列联表,交叉表)
- 交叉表、行列转换和交叉查询经典
- mysql 行列动态转换的实现(列联表,交叉表)
- C#行列转换(交叉表)处理源代码
- 交叉表、行列转换和交叉查询经典
- 实现行列间转换需求
- 简单行列转换记录
- Sql Server 2005 PIVOT的行列转换应用实例
- SQLServer行列转换 Pivot UnPivot
- SQL行列转换
- SQL 行列转换
- 拆分字段,并将其行列转换
- mysql行列转换方法总结
- 行列转换小结 Pivot ,Unpivot (转,改)
- 每日学习心得:SQL查询表的行列转换/小计/统计(with rollup,with cube,pivot解析)
- ORACLE行列转换
- sql游标实现行列转换
- 利用行列转换、外连接和笛卡尔积的一次完美统计
- c# 对于批量表的统一查询 WM_CONCAT行列转换行数