如何在每个部门的底部放置空值? [英] How to place Null Values at the Bottom of each Department?
问题描述
我正在写一个存储过程,我希望在每个部门的底部显示空值
。
情景
------------------- -----------------
ID |名称|费用|部门|
--- | ---------------- | ------ | ------- |
1 | a | 15 | 1 |
2 | b | 10 | 1 |
nul |总计| 25 | |
5 | c | 5 | 2 |
nul |总计| 5 | |
7 | d | 2 | 3 |
nul |总计| 2 | |
------------------------------------
@tbl我从订单表中获取所有价值
n
在@ tbl2中我正在使用按部门分组获取总和(成本)。
然后我使用了工会全部
select * from @tbl
union all
select * from @ tbl1
一个是显示空值的第一个值,按部门排序。
但我想显示第一个值然后显示空值,
命令由dept (例如,如上表所示)。
任何人都可以帮我在sql中获取此表,我可以显示空值
在每个部门的底部。
谢谢
添加:
ORDER BY ISNULL(部门) ,-1) DESC
Hi,
I'm write a stored procedure where i want to display null values at the bottom of
each department.
Scenario
------------------------------------ ID | Name | cost | Dept | ---|----------------|------|-------| 1 | a | 15 | 1 | 2 | b | 10 | 1 | nul| Total | 25 | | 5 | c | 5 | 2 | nul| Total | 5 | | 7 | d | 2 | 3 | nul| Total | 2 | | ------------------------------------
in @tbl i'm fetch all the values from the order table
n
in @tbl2 i'm fetching the total of sum(cost) using group by dept.
then i have used union all
select * from @tbl union all select * from @tbl1
This one is displaying null values first values, order by dept.
But i want to display first values then null values,
order by dept(eg. as above table).
can any one please help me to get this table in sql where i can display null values
at the bottom of each department.
Thanks解决方案Add:
ORDER BY ISNULL(Dept, -1) DESC
这篇关于如何在每个部门的底部放置空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!