【问题标题】:I have Multiple SQL queries how to store all query results and display it in table form我有多个 SQL 查询如何存储所有查询结果并以表格形式显示
【发布时间】:2020-04-21 07:41:00
【问题描述】:

我有多个查询,例如

query1=select StudentName from student limit 1;

query2=select StudentAge from student limit 2;

我想要类似的东西

category        value
StudentName    query1 result
StudentAge     query2 result

【问题讨论】:

  • 'something like' 有点含糊,你到底想要什么?选择 1 个“随机”学生和 2 个“随机”年龄有什么可能的价值?
  • 我想在一个表中存储多个查询结果
  • 请阅读stackoverflow.com/help/how-to-ask将表格定义、示例数据和预期结果作为文本添加到问题中。

标签: mysql sql mysql-workbench


【解决方案1】:

为了说明你离一个好问题还有多远,这里的答案完全符合你的问题,但可能是绝对垃圾。

drop table if exists student;
drop table if exists t;

create table student(id int, studentname varchar(3), studentage int);
create table t(val varchar(4));
insert into student values
(1,'aaa',19),(2,'bbb',19),(3,'ccc',30),(5,'ddd',20);

insert into  t
select * from
(
select StudentName from student limit 1
) a
union all
(
select StudentAge from student limit 2
) ;

select * from t;

+------+
| val  |
+------+
| aaa  |
| 19   |
| 19   |
+------+
3 rows in set (0.001 sec)

【讨论】:

    猜你喜欢
    • 2012-09-20
    • 2011-04-13
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多