簡體   English   中英

mysql選擇,計數,左聯接並顯示

[英]mysql select, count, left join and show

我必須進行mysql詢問,並且必須按日期計數一些具有相同值的單元格,並從其他表中加入其他信息。

表格1

col1 | col2     | col3
ALEX | today    | finished
JOHN | today    | finished
TIM  | today    | finished
JOHN | today    | unfinished
JOHN | today    | finished
TIM  | tommorow | finished

表2

col4 | col5
ALEX | mail1@website.tld
JOHN | mail1@website.tld
TIM  | mail1@website.tld

我嘗試了這段代碼:

sql="
SELECT col2
     , col1
     , col3
     , COUNT(*) 
  FROM table1 
  LEFT 
  JOIN table2  
    ON table1.task_cine = table2.col4 
 WHERE table1.col3='finished' 
 GROUP 
    BY col1";
$result = mysql_query($sql) or die($sql.mysql_error());
while($rows=mysql_fetch_array($result))
{
    echo "user : ";
    echo $rows['col1'];
    echo ", on date: ";
    echo $rows['col2'];
    echo " have ";
    echo $row['COUNT(*)'];
    echo " finished, and have email address";
    echo $rows['col5'];
}

你能幫我嗎? 我試圖了解php,但是很難。

嘗試:-
mysql_fetch_assoc($ result)

代替mysql_fetch_array($ result)

要么

將索引與數組參數一起用於mysql_fetch_array($ result)

如$ rows [0],$ rows [1]

嘗試這個:

$sql="
SELECT col1
     , col2
     , col5
     , COUNT(*) 
  FROM table1 
  LEFT 
  JOIN table2  
    ON table1.task_cine = table2.col4 
 WHERE table1.col3='finished' 
 GROUP 
    BY col1";
$result = mysql_query($sql) or die($sql.mysql_error());
while($rows=mysql_fetch_array($result))
{
    echo "user : ";
    echo $rows['col1'];
    echo ", on date: ";
    echo $rows['col2'];
    echo " have ";
    echo $rows['COUNT(*)'];
    echo " finished, and have email address";
    echo $rows['col5'];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM