Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

sql - How to get two columns from mysql dynamic table

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

dynamic table

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

enter image description here

is it possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...