mysql连接和计数字段值

时间:2018-03-02 20:11:53

标签: mysql join

使用mysql非常新,所以如果这个问题非常简单,请原谅。如果有人能够至少提出我应该研究的主题,那就太好了。

我有3个表,用户,计算机,组件。 (这只是一个例子)。

user        computer      component
----        -------       ----
id          id            id
firstName   user_id       computer_id
lastName    name          componentName
            type          componentValue  

用户可能拥有多台计算机,而这些计算机又可能具有多个属性。

我正在尝试编写一个查询,该查询可以让所有用户ID都拥有他们所有的' Macintosh'计算机包含所有“ram”。具有' 16GB'的组件值。

到目前为止,我正在努力使得计数正确,但是写了类似的东西:

select user.id from user
inner join computer on user.id=computer.user_id and computer.name='Macintosh' 
inner join component on computer.id=component.computer_id and component.componentName='ram'
having count(component.propertyName='ram')=count(component.propertyValue='16GB');

提前感谢任何建设性的反馈。

1 个答案:

答案 0 :(得分:0)

您可以过滤componentValue =' 16GB'

production.rb

如果您只想使用只有16GB内存的计算机,则可以使用

config.action_cable.url = 'wss://my-domain.org:8080/cable'
config.web_socket_server_url = "wss://my-domain.org:8080/cable"