如何在MySQl中比较有计数和子请求

时间:2016-03-16 23:25:57

标签: mysql sql

我试图比较2个值,第一个将是一个请求中的count(),而第二个是来自另一个请求/表的字段值,但它们必须相关。这是我正在尝试的内容:

// This id for AJAX
<div id="addAdv">

  //This form for JavaScript.onclick and for upload request
  <form id="formAddAdv" method="post" enctype="multipart/form-data" action="upload">

   <fieldset>

    //Upload input with name
    <input type="file" name="upl"/>

    //Some data to send using AJAX
    <label for="inputAdvName">Title</label>
    <input id="inputAdvName" type="text" /><br/>
    <label for="inputStatus">Description</label>
    <textarea id="inputStatus"></textarea><br/>

    <input type="submit" value="Send"/>
  </fieldset>
 </form>
</div>

$('#formAddAdv').submit(addAdv);

其中lead_id和id_c是相同的ID但来自2个不同的表。

谢谢!

2 个答案:

答案 0 :(得分:0)

touches_phone_c是一个值为Number的字段。 我实际上想要得到的tou_id_phone_c的数量与第一次查询的结果数不同的lead_id

比方说,我的第一个查询给出了这个结果: '2','1001418c-a1d0-e422-de2a-54f63015d194'(2是计数的结果,'1001 ..'是lead_id) '1','1004a79b-30ca-072f-ef64-54b850e313e7' '1','1007d774-095b-e1aa-cbc5-5445cd09166a'

在我的第二个查询中,我想查看具有完全相同ID的字段“touches_phone_c”(因为这两个表都是相关的:lead_calls表的lead_id和leads_cstm表的id_c)

谢谢

答案 1 :(得分:0)

试试这个:

try
{
    string MyConnection1 = "datasource=localhost;port=3306;username=root;password=123";
    string Query1 = "insert into myproject.song " +
                        "(song_name, house_number, song_text) " +
                      "values " +
                        "('" + line1 + "', '" + paragraphs.Length + 
                          "', '" + filetext + "');" + //Insert song name, song huose count and full song text
                    "insert into myproject.file " +
                        "(File_Location, Words_number, Lines_number, File_name, song_id) " +
                      "values " +
                        "('" + strfilename + "','" + words.Length + "','" + 
                          totallineCnt + "', '" + fileNameOnly + 
                          "', ?????????????;";  //Insert table file details                          
    MySqlConnection myConn1 = new MySqlConnection(MyConnection1);
    MySqlCommand MyCommand1 = new MySqlCommand(Query1, myConn1);
    MySqlDataReader MyReader1;
    myConn1.Open();
    MyReader1 = MyCommand1.ExecuteReader();
    while (MyReader1.Read())
    {
    }
    myConn1.Close();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}