dsvjw20866 2018-01-25 07:21
浏览 74

如何将值与列名相同的多个表中的列值进行比较?

I have five different tables with same column names in the database. I want to check whether a string value matches with the column value of any of the five table.

For example: I have database that contains exam results of 8th standard. Five different table contains marks of each student. The first table contains marks of class 8th section A. The second table contains marks of class 8th section B. The Third table contains marks of class 8th section C. (So on)

All the table has same column names. (Roll no, math marks, history marks, Geography marks and Social study marks)

I want to fetch who have secured more than 90 in math. I want to know the single query of mysqli.

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • du59131 2018-01-25 07:28
    关注

    Assuming that the same students do not appear multiple tables, you should be able to take a union of the five tables (but see below for some comments on your design):

    SELECT *
    FROM table1
    WHERE math_marks > 90
    UNION ALL
    SELECT *
    FROM table2
    WHERE math_marks > 90
    UNION ALL
    SELECT *
    FROM table3
    WHERE math_marks > 90
    UNION ALL
    SELECT *
    FROM table4
    WHERE math_marks > 90
    UNION ALL
    SELECT *
    FROM table5
    WHERE math_marks > 90;
    

    A better design here would be to have a single table containing all student marks. You could have a column for the student ID, section, and class. This would make querying and keeping track of things easier IMO.

    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错