如何从mysql动态表中获取两列 [英] How to get two columns from mysql dynamic table
本文介绍了如何从mysql动态表中获取两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个动态表,通过微风形式创建
I have a dynamic table which created by breezing form
> id record element title name type value
> 6131 627 6448 Date date Calendar 2017-05-15
> 6132 627 6453 Number num Text 4
> 6129 626 6448 Date date Calendar 2017-05-12
> 6130 626 6453 Number num Text 3
> 6127 625 6448 Date date Calendar 2017-05-10
> 6128 625 6453 Number num Text 1
我想通过joomla-plotalot组件创建一个图表,它在一个选择查询中询问2列结果,像
I want to create a chart by joomla-plotalot components which ask 2 columns result within one select query,like
> 2017-05-15 1
> 2017-05-12 3
> 2017-05-10 4
是否可能?
推荐答案
有一个简单的解决方案。使用具有别名的子查询将表加入自己。
There is a simple solution. Join the table to itself using subqueries with aliases.
SELECT
d.`value` AS `date`,
n.`value` AS `num`
FROM
(SELECT `record`, `value` FROM MyTable WHERE `name`='date') AS d
INNER JOIN
(SELECT `record`, `value` FROM MyTable WHERE `name`='num') AS n
USING (`record`);
这篇关于如何从mysql动态表中获取两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文