select a.event_name,count(a.id) as 数量,CONVERT(BIGINT,COUNT(A.ID)/count(b.id)) AS 发生率 from hd_dialysis_event a,hd_treatment b where a.treatment_id=b.id and a.record_time>=@a_begin_date and a.record_time<=@a_end_date and b.traetment_date>=@a_begin_date and b.traetment_date<=@a_end_date group by a.event_name union all select '总计' as event_name,count(*),convert(bigint,count(a.id)/count(b.id)) 发生率 from hd_dialysis_event a ,hd_treatment b where a.treatment_id=b.id and a.record_time >=@a_begin_date and a.record_time<=@a_end_date and b.traetment_date>=@a_begin_date and b.traetment_date<=@a_end_date
时间: 2023-05-25 16:04:06 浏览: 125
BigInt_cpp.rar_BigInt.cpp
Explanation:
This SQL query retrieves data from the "hd_dialysis_event" and "hd_treatment" tables for a particular date range. It counts the number of events that occurred for each event name and calculates the occurrence rate. The result is then combined with the total count and occurrence rate for all events.
The query uses the "GROUP BY" clause to group the data by event name and then "UNION ALL" to combine it with the total count and occurrence rate. It also uses the "CONVERT" function to convert the occurrence rate to a "BIGINT" data type.
The "@" symbol before the parameter names indicates that they are user-defined parameters that can be passed to the query. This allows the user to specify the date range for which they want to retrieve the data.
阅读全文