| |

VerySource

 Forgot password?
 Register
Search
View: 987|Reply: 4

About sql take maximum date

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-30 10:20:01
| Show all posts |Read mode
For example:

Number of customers date
Zhang San 100 2016-02-25
Li Si 200 2016-03-21
Zhang San 50 2016-10-21
Zhang San 150 2016-09-14
Li Si 100 2016-06-26

Hopefully the result is:

Number of customers date
Zhang San 300 2016-10-21
Li Si 300 2016-06-26
Reply

Use magic Report

0

Threads

46

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-3-12 14:15:01
| Show all posts
group by
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

Post time: 2020-3-16 20:45:01
| Show all posts
First have a master ID
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-30 09:15:01
| Show all posts
select customer, sum (quantity) as a1, max (date) as a2 from table group by customer
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-8-5 11:30:01
| Show all posts
The statement is like this

select right(customer,len(customer)-charindex('-',customer)) as customer, quantity, date
FROM
(
    select distinct customers, null as quantity, date from tb_cat
    union
    select customer+'-'+product number, sum (quantity), date from tb_cat group by customer, product number
) T
order by customer
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