postgresql自我加入

tbh*_*bh1 7 postgresql join

说我有一张这样的桌子

  id  |     device     |  cmd  | value | 
------+----------------+-------+---------

id = unique row ID
device = device identifier (mac address)
cmd = some arbitrary command
value = value of corresponding command
Run Code Online (Sandbox Code Playgroud)

我想以某种方式自我加入此表以获取特定设备的特定cmds及其对应值.

我不想要 SELECT cmd,value FROM table WHERE device='00:11:22:33:44:55';

假设我想要的值对应于getname和getlocation命令.我想输出类似的东西

        mac         |    name   | location
--------------------+-----------+------------
 00:11:22:33:44:55  | some name | somewhere
Run Code Online (Sandbox Code Playgroud)

我的sql fu很漂亮.我一直在尝试不同的组合,SELECT a.value,b.value FROM table AS a INNER JOIN table AS b ON a.device=b.device但我无处可去.

谢谢你的帮助.

Mic*_*ker 10

SELECT a.value AS thisval ,b.value AS thatval
FROM table AS a JOIN table AS b USING (device)
WHERE a.command='this' AND b.command='that';
Run Code Online (Sandbox Code Playgroud)