Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.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
Php 从表中选择不同的列_Php_Mysql_Database_Laravel - Fatal编程技术网

Php 从表中选择不同的列

Php 从表中选择不同的列,php,mysql,database,laravel,Php,Mysql,Database,Laravel,我的数据库结构如下图所示: 我想检索属于特定产品\u id 例如: 假设1和Size=L,Color=Green 我希望mysql查询返回variant_id=7 此场景中预期使用的查询是什么? 您可以使用以下查询。 我假设您的表名为table1 select variant_id from (select * from table1 where product_id=1 and ((attribute_name='Size' and value='L') or (attribute_name

我的数据库结构如下图所示:

我想检索属于特定
产品\u id

例如:

假设1和
Size=L
Color=Green

我希望mysql查询返回variant_id=7

此场景中预期使用的查询是什么?


您可以使用以下查询。 我假设您的表名为
table1

select variant_id from (select * from table1 where 
product_id=1 and ((attribute_name='Size' and value='L')
or (attribute_name='Color' and value='Green'))) as temp 
group by variant_id having count(*)>1

非常感谢你。它很有魅力。你让我开心