如何做这个查询?
我有这些列的MySQL表:如何做这个查询?
- ID(自动递增)
- ID_BOOK(INT)
- 价格(双)
- DATA(日期)
我知道两个ID_BOOK值,例如,1和2
QUERY:
我必须提取所有PRICE(的ID_BOOK = 1和ID_BOOK = 2),其中DATA是一样的!
表例如:
1 1 10.00 2010-05-16 2 1 11.00 2010-05-15
3 1 12.00 2010-05-14
4 2 18.00 2010-05-16
5 2 11.50 2010-05-15
结果例子:
1 1 10.00 2010-05-16 4 2 18.00 2010-05-16
2 1 11.00 2010-05-15
5 2 11.50 2010-05-15
ID_BOOK = 2具有不2010-05-14
,所以我跳它。
非常感谢!
回答:
我已经猜出了你想要的结果,你需要用你的表的实际名称替换myTable
。
SELECT * FROM myTable
WHERE DATA IN
(
SELECT
DATA
FROM myTable
GROUP BY
DATA
HAVING COUNT(*) > 1
)
ORDER BY
DATA DESC,
ID_BOOK,
ID
回答:
select PURCHASE_DATE, PRICE from table group by PURCHASE_DATE
回答:
这会给你的结果略有不同的格式,但它可能是有用的:
Select t1.id as t1_id, t1.id_book as t1_id_book, t1.price as t1_price, t1.data as t1_data,
t2.id as t2_id, t2.id_book as t2_id_book, t2.price as t2_price, t2.data as t2_data
from table t1
inner join table t2 on t1.data = t2.data
and t1.id_book = 1
and t2.id_book = 2
你会得到:
1 1 10.00 2010-05-16 4 2 18.00 2010-05-16 2 1 11.00 2010-05-15 5 2 11.50 2010-05-15
以上是 如何做这个查询? 的全部内容, 来源链接: utcz.com/qa/265314.html