SQL查询:查找平均值

时间:2014-01-07 08:40:17

标签: sql sql-server

我是sql的初学者,我遇到了一个问题: 假设我有以下表格:

  • SIGNALS - 定期从芯片发送(KEY:(chip_id REF chips,signal_number))
  • RECEIVERS - 信号接收器,可在其范围内接收信号的电台(KEY:receiver_id)
  • RECEIVINGS - 接收信号的事实(KEY:Chip_id,signal_number,receiver_id)

我想知道是否有任何方法不使用php进行显示已接收信号百分比的查询。 任何帮助将不胜感激:)

1 个答案:

答案 0 :(得分:0)

SELECT 
 CAST((SELECT DISTINCT COUNT(*) FROM RECEIVINGS)AS FLOAT)/(SELECT COUNT(*) FROM SIGNALS),
 (SELECT COUNT(*) FROM RECEIVINGS), 
 (SELECT COUNT(*) FROM SIGNALS)