Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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 Sql查询-无法选择行的最大值_Mysql - Fatal编程技术网

Mysql Sql查询-无法选择行的最大值

Mysql Sql查询-无法选择行的最大值,mysql,Mysql,我有这个查询,显示我的网站中的项目 $sql = " select p.id , p.name , p.logo , p.short_description , c.Parent_category , IF(d.commission_name = 'percent' , CONCAT(FORMAT(d.action, 2)/2 ,' %') , CONCAT(FORMAT(d.action,2)/

我有这个查询,显示我的网站中的项目

    $sql = "
select p.id
     , p.name
     , p.logo
     , p.short_description
     , c.Parent_category
     , IF(d.commission_name = 'percent'
          , CONCAT(FORMAT(d.action, 2)/2 ,' %') 
          , CONCAT(FORMAT(d.action,2)/2,' €')) as comms
     , GROUP_CONCAT(c.category_name SEPARATOR ',') as category_names  
  from eshop p  
  join eshop_cat c 
    on p.id = c.eshop_id 
  join eshop_commissions d 
    on p.id = d.eshop_id 
 where c.Parent_category = 'fashion'
   and p.sites = 1  
 GROUP 
    BY d.action DESC 
";
问题就在这里

IF(d.commission_name = 'percent', CONCAT(FORMAT(d.action, 2)/2 ,' %') , 
    CONCAT(FORMAT(d.action,2)/2,' €'))
我只需要每个eshop id的最大值。我尝试了这个

IF(d.commission_name = 'percent', CONCAT(FORMAT(max(d.action), 2)/2 ,' %') , 
CONCAT(FORMAT(max(d.action),2)/2,' €'))
但它不起作用

例如,我有两个条目具有相同的eshop id 我怎么能只收到一个佣金,这将是最大的

eshop_id commission_name action
       1 percent             20 (%)
       1 fixed_amount        30 (euro)
已编辑

CREATE TABLE `eshop` (
  `id` int(11) NOT NULL,
  `name` text NOT NULL,
  `logo` text NOT NULL,
  `short_description` text NOT NULL,
  `sites` tinyint(1) NOT NULL,
  `url` text NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `summary` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `eshop_commissions` (
  `commission_name` text NOT NULL,
  `eshop_id` int(11) NOT NULL,
  `action` decimal(10,2) NOT NULL,
  `subaction` decimal(10,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `eshop_cat` (
  `eshop_id` int(11) NOT NULL,
  `category_name` text NOT NULL,
  `Parent_category` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `eshop_commissions` (`commission_name`, `eshop_id`, `action`, `subaction`) VALUES
('percent', 100, '12.00', '12.00'),
('fixed_amount', 100, '15.00', '15.00'),
('percent', 100, '5.00', '5.00'),
('percent', 100, '2.00', '2.00');



INSERT INTO `eshop` (`id`, `name`, `logo`, `short_description`, `description`, `sites`, `url, `timestamp`, `summary`) VALUES
(100, 'Tokotoukan', 'logo-tokotoukan.gif', '<p>\r\n !</p>\r\n', '<p>\r\n    <font face=\"arial\" size=\"2\">Τo TOKOTOUKAN </font></p>\r\n', 1, 'http://www.com', ''2017-07-07 17:39:59', '15,00%');

INSERT INTO `eshop_cat` (`eshop_id`, `category_name`, `Parent_category`) VALUES
(100, 'fashion', 'fashion');
创建表“eshop”(
`id`int(11)不为空,
`name`文本不为空,
`logo`文本不为空,
`简短描述`文本不为空,
`站点'tinyint(1)不为空,
`url`文本不为空,
`timestamp` timestamp NOT NULL更新当前时间戳时的默认当前时间戳,
`摘要`文本不为空
)ENGINE=InnoDB默认字符集=utf8;
创建表“eshop_佣金”(
`佣金名称`文本不为空,
`eshop_id`int(11)不为空,
`动作`十进制(10,2)不为空,
`子动作`十进制(10,2)不为空
)ENGINE=InnoDB默认字符集=utf8;
创建表“eshop_cat”(
`eshop_id`int(11)不为空,
`类别名称`文本不为空,
`父类`文本
)ENGINE=InnoDB默认字符集=utf8;
在'eshop'u commissions'('commission'u name`、'eshop'u id`、'action`、'subaction`)值中插入
(‘百分比’、100、‘12.00’、‘12.00’),
(‘固定金额’、100、‘15.00’、‘15.00’),
(‘百分比’、100、‘5.00’、‘5.00’),
(‘百分比’、100、‘2.00’、‘2.00’);
在“eshop”(`id`、`name`、`logo`、`short_description`、`description`、`sites`、`url、`timestamp`、`summary`)值中插入
(100,'Tokotoukan','logo Tokotoukan.gif','\r\n!

\r\n','\r\n'o Tokotoukan

\r\n',1,'http://www.com', ''2017-07-07 17:39:59', '15,00%'); 在'eshop_cat`('eshop_id`、'category_name`、'Parent_category`)值中插入 (100,“时尚”、“时尚”);
这里有几个问题。请参阅我添加了一些信息。感谢进度报告。数据集与预期结果之间没有明显的相关性。同一个eshop id有多个佣金。我只希望使用十进制10.2格式选择更高的佣金