Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mysql语句中创建多个计数_Mysql_Join_Count - Fatal编程技术网

如何在mysql语句中创建多个计数

如何在mysql语句中创建多个计数,mysql,join,count,Mysql,Join,Count,我很难在mysql语句中计数超过2个 我的计数(b.entry\u id)为totalbooking不起作用。我做错了什么?语句设置是否正确​​? 我就是这样尝试的: "SELECT t.restaurant_id as restaurant_id, ct.title as title, count(DISTINCT t.cardid) as totalmembers, count(t.restaurant_id) as totaltransactions,

我很难在mysql语句中计数超过2个

我的
计数(b.entry\u id)为totalbooking
不起作用。我做错了什么?语句设置是否正确​​?

我就是这样尝试的:

"SELECT 
    t.restaurant_id as restaurant_id, ct.title as title, 
    count(DISTINCT t.cardid) as totalmembers, 
    count(t.restaurant_id) as totaltransactions, 
    count(b.entry_id) as totalbooking
    from transactions as t   
    inner join exp_menucard_booking as b on (t.restaurant_id = b.entry_id)
    inner join exp_channel_titles as ct on (t.restaurant_id = ct.entry_id)
    inner JOIN exp_channel_data as cd on (ct.entry_id = cd.entry_id)
    where t.cardid != 88888888 and ct.status = 'open'
    group by t.restaurant_id
    order by ct.title asc";

使用此模式计算整个行集的子集:

sum( case when ColumnToBeTested = trueCondition then 1 else 0 end) as SubCount

你说的“不工作”是什么意思?算上(b.entry\u id),因为totalbooking不算。其他一切都很好。