gpt4 book ai didi

mysql - 如何从多个查询中进行乘法和除法?

转载 作者:行者123 更新时间:2023-11-30 00:57:02 30 4
gpt4 key购买 nike

现在我有 3 个疑问:

我们将此查询称为 X

SELECT count(*) as totalDrink from 
Drink D join History H where H.drinkName = D.name AND type = 'vodka' and userID = 'sai'

查询Y

SELECT count(*) as totalDrink from 
Drink D join Favorite F where F.drinkName = D.name AND type = 'vodka' and userID = 'sai'

查询Z

SELECT SUM(totalDrinks) as total FROM (
SELECT COUNT(*) totalDrinks FROM History
WHERE userID = 'sai'
UNION ALL
SELECT COUNT(*) FROM Favorite
WHERE userID = 'sai'
) as totalDrink

基本上我想在 mySQL 中执行并输出:

(X + Y(0.666))/Z

最佳答案

最直接:

SELECT (
(
SELECT COUNT(*)
FROM Drink D JOIN History H ON H.drinkName = D.name
WHERE type = 'vodka' AND userID = 'sai'
) + (
SELECT COUNT(*)
FROM Drink D JOIN Favorite F ON F.drinkName = D.name
WHERE type = 'vodka' AND userID = 'sai'
)
) / (
(
SELECT COUNT(*) FROM History WHERE userID = 'sai'
) + (
SELECT COUNT(*) FROM Favorite WHERE userID = 'sai'
)
)

关于mysql - 如何从多个查询中进行乘法和除法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20461991/

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