| |

VerySource

 Forgot password?
 Register
Search
View: 1835|Reply: 2

Anxious, this SQL will not be written, please help me see how to write it?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-28 09:20:01
| Show all posts |Read mode
A table has three fields: a, b, and c. When b is empty, the meaning of a is "A". When b is not empty, the meaning of a is "B". Now I want Take out these two meanings at the same time and group them in C. How to take them?
I.e. the result column I took should be:
field c sum of field a representing "A" sum of field a representing "B"
c1 a1 a11
c2 a2 a22


By the way, my database is sysbase
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-6 22:45:01
| Show all posts
select
  c,
  sum (case when b is null then 1 else 0 end) A,
  sum (case when b is not null then 1 else 0 end) B
from
  yourtable
group by
  c
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-8-30 14:45:01
| Show all posts
Thanks. . . .
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list