Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.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/7/sqlite/3.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
如何比较SQL(sqlite)中相同时间戳的结果?_Sql_Sqlite_Join - Fatal编程技术网

如何比较SQL(sqlite)中相同时间戳的结果?

如何比较SQL(sqlite)中相同时间戳的结果?,sql,sqlite,join,Sql,Sqlite,Join,我在sqlite中有一个简单的表,如下所示: dt | ab | price ----------------------------- 2014-01-06 21:57:00 | a | 86 2014-01-06 21:57:00 | b | 89 2014-01-06 21:58:00 | b | 84 2014-01-06 21:58:00 | a | 82 2014-01-06 21:59:00 | a | 82 2014-01-06 21:

我在sqlite中有一个简单的表,如下所示:

dt                  | ab | price
-----------------------------
2014-01-06 21:57:00 | a  | 86
2014-01-06 21:57:00 | b  | 89
2014-01-06 21:58:00 | b  | 84
2014-01-06 21:58:00 | a  | 82
2014-01-06 21:59:00 | a  | 82
2014-01-06 21:59:00 | b  | 66
dt                  | price of a | price of b
----------------------------------------------
2014-01-06 21:57:00 | 86         | 89
2014-01-06 21:58:00 | 82         | 84
2014-01-06 21:59:00 | 82         | 66
所以每次约会,我都会从“a”和“b”得到一个价格。我现在想得到一份清单,在其中我可以很容易地比较如下价格:

dt                  | ab | price
-----------------------------
2014-01-06 21:57:00 | a  | 86
2014-01-06 21:57:00 | b  | 89
2014-01-06 21:58:00 | b  | 84
2014-01-06 21:58:00 | a  | 82
2014-01-06 21:59:00 | a  | 82
2014-01-06 21:59:00 | b  | 66
dt                  | price of a | price of b
----------------------------------------------
2014-01-06 21:57:00 | 86         | 89
2014-01-06 21:58:00 | 82         | 84
2014-01-06 21:59:00 | 82         | 66
我试过这样做:
选择dt,按dt从价格组中选择价格,但无效。我理解为什么这不起作用,但我真的不知道如何正确地做。我想我需要使用连接之类的东西,但我对SQL不是很精通


有谁能告诉我如何做到这一点吗?

您想要条件聚合:

SELECT dt,
       max(case when ab = 'a' then price end) as a_price,
       max(case when ab = 'b' then price end) as b_price
FROM prices
GROUP BY dt;