gpt4 book ai didi

Mysql:多行比较

转载 作者:行者123 更新时间:2023-12-01 00:05:09 26 4
gpt4 key购买 nike

来自这个 Mysql 表:

Attributes
Brand |attr | vals
Samsung | RAM | '750'
Samsung | CPU | '1200'
HTC | RAM | '1000'
HTC | CPU | '1500'

我不知道如何获取所有项目

RAM>500
CPU>1300

作为结果,我只需要匹配所有参数的品牌:

Attributes
Brand |attr | vals
HTC | * | *

查看 SQL fiddle : http://sqlfiddle.com/#!2/491d7/1

最佳答案

我将通过旋转数据获得结果:

select brand, RAM, CPU
from
(
select brand,
max(case when attr='RAM' then cast(vals as unsigned) end) as RAM,
max(case when attr='CPU' then cast(vals as unsigned) end) as CPU
from attributes
group by brand
) d
where RAM > 500
and CPU > 1300

参见 SQL Fiddle with Demo

关于Mysql:多行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15797718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com