|
1
|
| den bardadym hakatashi · 技术社区 · 15 年前 |
|
|
1
1
I would just do a normal select with a GROUP BY over the month and have your UI handle displaying it as 12 columns across. If you really need to do it though, then this should work:
You might need to change the date functions based on your RDBMS. Also, you may need to fiddle with the edge cases - if your dates have a time component it won't catch rows on 12/31. 最后,我不知道RDBMS和我之间的这种变化是否现在无法测试,但是如果AVG将空值计算为0成本而不是折扣它们,那么您可能需要做您自己的averag-sum(case…成本…0)/总和(大小写…1…0)。我希望这是有道理的。 |
|
|
2
2
Try the following. You may need to modify the date functions depending on your RDBMS. I have assumed MySQL, but the rest should be universal SQL.
Note, this may only include months for doctors that have visits. So you may need to use
|
|
|
3
1
您可以像下面这样轻松地完成这项工作,但它会在单独的一行中列出每个月的成本。如果您希望将成本放在同一行,则可以使用PIVOT语句。对于SQL 2008,如果需要进行数据透视,则可以这样做。如果存在性能问题,请使用日期范围扫描,而不是使用日期部分扫描。
|
|
|
Johnny T · 基于当前值的SQL合并表[重复] 8 月前 |
|
John D · 需要为NULL或NOT NULL的WHERE子句 8 月前 |
|
ojek · 如何对SQL结果进行分组和编号? 8 月前 |
|
|
senek · 如何在PL/SQL中将选择结果(列)放入数组中 8 月前 |
|
|
Sax · 规范化Google表格(第一步) 8 月前 |
|
|
Jatin · 检索卷计数的动态sql抛出错误语法错误[关闭] 8 月前 |
|
|
Andrus · 如何在sql中查找第二个匹配项 9 月前 |