• <small id='gcwAf'></small><noframes id='gcwAf'>

      <legend id='gcwAf'><style id='gcwAf'><dir id='gcwAf'><q id='gcwAf'></q></dir></style></legend>
    1. <tfoot id='gcwAf'></tfoot>
    2. <i id='gcwAf'><tr id='gcwAf'><dt id='gcwAf'><q id='gcwAf'><span id='gcwAf'><b id='gcwAf'><form id='gcwAf'><ins id='gcwAf'></ins><ul id='gcwAf'></ul><sub id='gcwAf'></sub></form><legend id='gcwAf'></legend><bdo id='gcwAf'><pre id='gcwAf'><center id='gcwAf'></center></pre></bdo></b><th id='gcwAf'></th></span></q></dt></tr></i><div id='gcwAf'><tfoot id='gcwAf'></tfoot><dl id='gcwAf'><fieldset id='gcwAf'></fieldset></dl></div>
          <bdo id='gcwAf'></bdo><ul id='gcwAf'></ul>

        SQL 选择字符串不起作用

        时间:2023-10-11
        <i id='3oH1y'><tr id='3oH1y'><dt id='3oH1y'><q id='3oH1y'><span id='3oH1y'><b id='3oH1y'><form id='3oH1y'><ins id='3oH1y'></ins><ul id='3oH1y'></ul><sub id='3oH1y'></sub></form><legend id='3oH1y'></legend><bdo id='3oH1y'><pre id='3oH1y'><center id='3oH1y'></center></pre></bdo></b><th id='3oH1y'></th></span></q></dt></tr></i><div id='3oH1y'><tfoot id='3oH1y'></tfoot><dl id='3oH1y'><fieldset id='3oH1y'></fieldset></dl></div>
        • <bdo id='3oH1y'></bdo><ul id='3oH1y'></ul>
                <tbody id='3oH1y'></tbody>
              1. <tfoot id='3oH1y'></tfoot>

                1. <legend id='3oH1y'><style id='3oH1y'><dir id='3oH1y'><q id='3oH1y'></q></dir></style></legend>
                2. <small id='3oH1y'></small><noframes id='3oH1y'>

                  本文介绍了SQL 选择字符串不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经发布了这个,但我想更好地解释它.我有一个网站,学生在其中插入他们的 4 门课程和每门课程的 4 条评论,这些是 SQL 表列:课程 1、课程 2、课程 3、课程 4、评论 1、评论 2、评论 3、评论 4.

                  我有一个搜索,任何学生都可以在其中输入地理(可以保存在四个课程列中的任何一个中),并且我希望我的 SQL 查询返回地理的所有评论.例如,如果学生在 Course2 位置保存了 Geography,我希望我的 SQL 查询选择 comment2,其中 course2 = geography.他可能已经保存在course1中了,所以要灵活一些,但只能选择学生选择的课程.这是我当前的 SQL 查询:

                  $SQL = "SELECT (Comment1 FROM Students WHERE Course1 = 'geography'), (Comment2 FROM Students WHERE Course2 = 'geography'), (Comment3 FROM Students WHERE Course3 = 'geography'), (Comment4 FROM学生 WHERE Course4 = '地理')";

                  目前,此 SQL 查询不起作用.我知道这种结构可能看起来很奇怪,但从逻辑上讲,正如您可能理解的那样,这是有道理的,尽管这可能不是正确的编码方式.然后我像这样打印所有的地理评论:

                  $null = '';if(mysql_num_rows($result)) {echo "

                    ";而 ($row=mysql_fetch_array($result)) {if($row["Class"]!=$null) {if($null!='') {echo "</ol><ol type='1'>";}}echo "<li><p>"."".$row["Comment1"]."".$row["Comment2"]." " .$row["Comment3"] ."".$row["Comment4"] ."</li></p>";$i = $i +1;}echo "</ol>";

                  解决方案

                  假设表结构真的(原文如此)不能改变(不再)我会选择 UNION 这里

                   ( SELECT Comment1 as comment FROM soFoo WHERE Course1='geography' )联合所有( SELECT Comment2 as comment FROM soFoo WHERE Course2='geography' )联合所有( SELECT Comment3 as comment FROM soFoo WHERE Course3='geography' )联合所有( SELECT Comment4 as comment FROM soFoo WHERE Course4='geography' )

                  它至少给 MySQL 一个使用索引查找匹配记录的机会.

                  I've already posted this but I want to explain it better. I have a website in which students insert their 4 courses and 4 comments for each course, these are the SQL table columns: Course1, Course2, Course 3, Course 4, Comment1, Comment2, Comment 3, Comment 4.

                  I have a search in which any student inputs, for instance, geography (which may be saved in any of the four course columns), and I want my SQL query to return all the comments for geography. For example, if a student saved Geography in position Course2, I want my SQL query to select comment2 where course2 = geography. He may have saved it in course1, so it has to be flexible, but only select the course chosen by the student. This is my current SQL query:

                  $SQL = "SELECT (Comment1 FROM Students WHERE Course1 = 'geography'), (Comment2 FROM Students WHERE Course2 = 'geography'), (Comment3 FROM Students WHERE Course3 = 'geography'),  (Comment4 FROM Students WHERE Course4 = 'geography')";
                  

                  Currently, this SQL query isn't working. I know the structure may seem odd, but logically, as you may understand, this makes sense, though it's probably not the right way to code it. I then print all the geography comments like this:

                  $null = '';
                  if(mysql_num_rows($result)) {
                    echo "<ol>";  
                   while ($row=mysql_fetch_array($result)) {
                    if($row["Class"]!=$null) {  
                    if($null!='') {  
                    echo "</ol><ol type='1'>";   
                    } 
                   }
                  
                   echo "<li><p>" . " " . $row["Comment1"]. " " . $row["Comment2"]." " .    $row["Comment3"] . " " . $row["Comment4"] . "</li></p>";
                  $i = $i +1;
                  }
                  
                  echo "</ol>";
                  

                  解决方案

                  Assuming that table structure really(sic) can't be changed (anymore) I'd go with a UNION here

                      ( SELECT Comment1 as comment FROM soFoo WHERE Course1='geography' )
                  UNION ALL
                      ( SELECT Comment2 as comment FROM soFoo WHERE Course2='geography' )
                  UNION ALL
                      ( SELECT Comment3 as comment FROM soFoo WHERE Course3='geography' )
                  UNION ALL
                      ( SELECT Comment4 as comment FROM soFoo WHERE Course4='geography' )
                  

                  It gives MySQL at least a fighting chance to use indices to find the matching records.

                  这篇关于SQL 选择字符串不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL STR_TO_DATE 函数不工作 下一篇:如果引擎是 MyISAM,则表中没有外键

                  相关文章

                  <tfoot id='I1dx2'></tfoot>

                  1. <i id='I1dx2'><tr id='I1dx2'><dt id='I1dx2'><q id='I1dx2'><span id='I1dx2'><b id='I1dx2'><form id='I1dx2'><ins id='I1dx2'></ins><ul id='I1dx2'></ul><sub id='I1dx2'></sub></form><legend id='I1dx2'></legend><bdo id='I1dx2'><pre id='I1dx2'><center id='I1dx2'></center></pre></bdo></b><th id='I1dx2'></th></span></q></dt></tr></i><div id='I1dx2'><tfoot id='I1dx2'></tfoot><dl id='I1dx2'><fieldset id='I1dx2'></fieldset></dl></div>

                      <small id='I1dx2'></small><noframes id='I1dx2'>

                      <legend id='I1dx2'><style id='I1dx2'><dir id='I1dx2'><q id='I1dx2'></q></dir></style></legend>
                        <bdo id='I1dx2'></bdo><ul id='I1dx2'></ul>