How to get two columns from mysql dynamic table

我怕爱的太早我们不能终老 提交于 2019-12-12 05:37:54

问题


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

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

is it possible?


回答1:


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`);


来源:https://stackoverflow.com/questions/44060426/how-to-get-two-columns-from-mysql-dynamic-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!