Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.85 KB | None | 0 0
  1.  
  2. select distinct item from arias
  3.  
  4. select f.item, f.qty, f.amount, sum(x.qty), sum(x.amount),
  5. f.qty-sum(x.qty), f.amount-sum(x.amount)
  6. from
  7. ( select * from x17cnn where month(date)=12 ) x join arias f
  8. on x.item=f.item
  9. group by f.item, f.qty, f.amount
  10.  
  11.  
  12. 555480
  13.  
  14. select top 10 * from x17cnn where month(date)=12
  15.  
  16. select * into #t from
  17. (select distinct item, name from b17cnn where supp='690'
  18. union select distinct item, name from b16cnn where supp='690'
  19. union select distinct item, name from b15cnn where supp='690') t
  20. go
  21.  
  22. select supp, sum(amount) from b17cnn
  23. where item in (select item from #t)
  24. group by supp
  25.  
  26. select x.item, sum(amount) from
  27. ( select * from x17cnn where month(date)=12 ) x join #t t on x.item=t.item
  28. group by x.item with rollup
  29. order by x.item
  30.  
  31.  
  32. select f.item, sum(x.amount)
  33. from ( select * from x17cnn where month(date)=12 ) x join arias f
  34. on x.item=f.item
  35. group by f.item with rollup
  36. order by f.item
  37.  
  38. select a.*, b_amt, a_amt-isnull(b_amt,0) diff into #a from
  39. ( select f.item, sum(x.amount) a_amt
  40. from ( select * from x17cnn where month(date)=12 ) x join arias f
  41. on x.item=f.item
  42. group by f.item ) a
  43. left join
  44. ( select x.item, sum(amount) b_amt from
  45. ( select * from x17cnn where month(date)=12 ) x join #t t on x.item=t.item
  46. group by x.item ) b
  47. on a.item=b.item where a_amt-isnull(b_amt,0) !=0
  48.  
  49. select f.item, sum(x.amount) a_amt
  50. from ( select * from x17cnn where month(date)=12 ) x join arias f
  51. on x.item=f.item
  52. group by f.item with rollup
  53.  
  54.  
  55. select item, name, sum(qty), sum(amount) from x17cnn where item in
  56. (select item from #b)
  57. group by item, name
  58.  
  59.  
  60. select * from b17cnn where item in
  61. ('315.0116')
  62.  
  63. select * from arias where item='315.0116'
  64.  
  65. select month(date), sum(amount) from x17cnn where item in (select item from #t)
  66. group by month(date)
  67.  
  68.  
  69.  
  70.  
  71. select * from b17cnn where item='315.0116'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement