SQL Server 中多个表的多个聚合函数
我正在尝试获取输入人员的数据,我想提取特定人员的发票数量和行项目数量等数据。
输出是
Entered_by No of line items
CD 9
CD 136084
deepa 7
deepa 18
dolly 757
dolly 22350
kroshni 666
kroshni 16161
lokesh 4
lokesh 999
MHeera 639
MHeera 20427
nandini 7
nandini 5318
这里的行项目数中的数据是“行项目数”计数和“发票数”计数的混合,我想显示类似
Entered_by No of line items No of invoices
CD 136084 9
deepa 18 7
dolly 22350 757
请帮我解决这个问题......
这是T- SQL查询
select ENTERED_BY, count(entered_by) 'NO OF LINE ITEMS'
from im_invoice, im_invoice_line_item, im_invoice_inventory
where invoice_rid = invoice_fk
and invoice_inventory_rid = invoice_inv_fk
and enter_date between dateadd(mm, -3, getdate()) and dateadd(mm,0,getdate())
group by entered_by
union
select entered_by, count(invoice_num) 'NO OF INVOICES' from im_invoice
where enter_date between dateadd(mm, -3, getdate()) and dateadd(mm,0,getdate())
group by entered_by
I am trying to get data for entered person, I want to pull out data as No of invoices and No of line items for particular person.
The output is
Entered_by No of line items
CD 9
CD 136084
deepa 7
deepa 18
dolly 757
dolly 22350
kroshni 666
kroshni 16161
lokesh 4
lokesh 999
MHeera 639
MHeera 20427
nandini 7
nandini 5318
Here the data in No of line items is mixing of both ’ No of line items’ count and ‘No of invoices’ count, I want to show like
Entered_by No of line items No of invoices
CD 136084 9
deepa 18 7
dolly 22350 757
Please help me with this somebody …..
Here is the T-SQL query
select ENTERED_BY, count(entered_by) 'NO OF LINE ITEMS'
from im_invoice, im_invoice_line_item, im_invoice_inventory
where invoice_rid = invoice_fk
and invoice_inventory_rid = invoice_inv_fk
and enter_date between dateadd(mm, -3, getdate()) and dateadd(mm,0,getdate())
group by entered_by
union
select entered_by, count(invoice_num) 'NO OF INVOICES' from im_invoice
where enter_date between dateadd(mm, -3, getdate()) and dateadd(mm,0,getdate())
group by entered_by
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如乔所说,如果您给我们更详细的描述,我们可以给您更好的答案,但在那之前,完成此操作的快速而肮脏的方法如下:
例如。
As Joe said, if you give us a more detailed description we can give you better answers, but until then, quick and dirty way to accomplish this is as follows:
Eg.