我有一张桌子:
PRICE
ticker date close
AAPL 3/20/2019 $100
AAPL 3/21/2019 $101.5
AAPL 3/22/2019 $106.5
GOOG 3/20/2019 $100
GOOG 3/21/2019 $130
GOOG 3/22/2019 $110
MSFT 3/20/2019 $184.5
MSFT 3/21/2019 $188.5
MSFT 3/22/2019 $210
IBM 3/20/2019 $72
IBM 3/21/2019 $70
IBM 3/22/2019 $10
我想知道在两种不同条件下比较行数并在计数相等时返回代码的正确方法。 (最终,仅当行军收盘价大于100时才返回股票行情)。所以:
SELECT ticker, COUNT(*) FROM PRICE WHERE close>100 group by ticker;
返回:
| ticker | COUNT(*) |
+--------+----------+
| AAPL | 2 |
| GOOG | 2 |
| MSFT | 3 |
和
SELECT ticker, COUNT(*) FROM PRICE group by ticker;
返回:
| ticker | COUNT(*) |
+--------+----------+
| AAPL | 3 |
| GOOG | 3 |
| MSFT | 3 |
因此,MSFT应该是返回到输出的唯一代码。
SQL的新手,任何建议将不胜感激!
答案 0 :(得分:0)
一种简单的方法通过股票代码进行汇总,并断言所有结束值均大于100:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
}