如何通过分组从内部联接中选择计数?
SELECT COUNT(table1.act) FROM table1
INNER JOIN table2 ON table1.act = table2.act
GROUP BY table1.act
Run Code Online (Sandbox Code Playgroud)
这将返回table2中找到的act的计数.
添加
SELECT table1.act, COUNT(table1.act) AS test
Run Code Online (Sandbox Code Playgroud)
返回
act test
------- ----
17682 3
17679 3
17677 3
11636 1
11505 1
Run Code Online (Sandbox Code Playgroud)
我想收到行为总数的计数.
所以我想得到5.你能帮忙吗?
我正在尝试创建我的第一个PHP类,并一直停留在如何更新受保护的字符串上。
我想做的是创建一个扩展类,该扩展类与主类中的受保护字符串一起使用。
加载第一个类时,我可以更新字符串,但是加载扩展类时,它不显示更新后的文本。
我究竟做错了什么?
class test {
protected $testing = 'test';
function __construct(){
echo "The Test class has loaded (".$this->testing.")";
$this->testing='changed';
echo "Updated to (".$this->testing.")";
}
}
class test2 EXTENDS test {
function __construct(){
echo "The Test2 class has loaded (".$this->testing.")";
$this->testing='updated';
echo 'The string has been updated to ('.$this->testing.')';
}
}
$blah = new test();
$blah2 = new test2();
Run Code Online (Sandbox Code Playgroud)
我想要得到的结果是:
Test类已经加载(测试),更新为(更改)
Test2类已加载(已更改)字符串已更新为(已更新)
是否有可能爆炸这样的数组.
$arr=array();
$arr[0]['id']='123';
$arr[0]['otherdatas']=
$arr[1]['id']='234';
$arr[1]['otherdatas']=
$arr[2]['id']='567';
echo "string: ".explode($arr[]['id'],',');
Run Code Online (Sandbox Code Playgroud)
并最终得到这个?
string: 123,234,567
Run Code Online (Sandbox Code Playgroud)
执行以上操作会导致:
致命错误:无法使用[]在第8行的/data/www/test.php中阅读
如果不做像......那样的事情我怎么能这样做呢?
function getIDs(){
foreach($arr as $val){
if($string){$string.=',';}
$string.=$arr['id'];
}
return $string;
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来解决这个问题?