| |

VerySource

 Forgot password?
 Register
Search
View: 1051|Reply: 9

Database table query? ? ? ? ?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Unknown

Post time: 2020-3-16 13:30:01
| Show all posts |Read mode
1. There is a table t1 with field names: t1_date, t1_telphone, t1_content
2. There is another table t2 with field names: t2_date, t2_telphone, t2_content
3. Find the total number of tables t1, t1_telphone and t2, t2_telphone of different dates.

Such as:
Date (t1_date) Total number of t1_telphone Total number of t2_telphone

January 1 20 15
January 2 14 17
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Unknown

Post time: 2020-7-6 22:15:01
| Show all posts
select count(t1_telphone) from t1
Reply

Use magic Report

1

Threads

51

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-7-11 08:30:01
| Show all posts
select count(t1_telphone) from t1,t2 where t1.t1_date=t2.t2_date
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-11 12:30:01
| Show all posts
DECLARE @bdate datetime;
declare @edate datetime
set @bdate='2016-12-01'
set @edate='2016-12-31'
if exists(
select * from tempdb.dbo.[sysobjects] where name like'#A%')
drop table #A
select getdate() as d into #A
delete #A

while @bdate<@edate
begin
set @bdate=dateadd(d,1,@bdate)
insert #A
select(@bdate) as date, (select count(t1_telphone) from t1 where t1_date between @bdate and @edate) as t1_telphone total,
(select count(t2_telphone) from t2 where t2_date between @bdate and @edate) as the total number of t2_telphone
end

select * from #A

/////////////////////
For ms sql server 2000, you can write a stored procedure to try
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-8 16:15:01
| Show all posts
lz, can the method I wrote for you work? Have you tried it? Why are you doing this? No response after posting. At least you can say something (still not).
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-8-8 16:45:01
| Show all posts
select t1.t1_date as mydate, sum(t1.t1_telephone) as t1phone, sum(t2.t2_telephone) as t2phone
from t1, t2
where t1.t1_date = t2.t2_date
group by t1.t1_date;
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-8-8 20:00:01
| Show all posts
很累的neo
sorry! I have seen what you did! But I have not tried it yet! I figured out another way! Don't worry, you should also take a look!
select SENDDATE,sum(T1),sum(T2) from
(select t1_date SENDDATE ,count(*) T1,0 T2 from t1 group by t1_date)union
(select t2_date ,0,count(*) from t2 group by t2_date))group by SENDDATE;
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-8 20:45:02
| Show all posts
SELECT t1.t1_date AS mydate, sum(t1.t1_telephone) AS t1phone, sum(t2.t2_telephone) AS t2phone
FROM t1, t2
WHERE t1.t1_date = t2.t2_date
GROUP BY t1.t1_date;
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-8 22:30:01
| Show all posts
lz:
For your needs, maybe your method is more suitable. No matter what, the problem is solved.
I may have spoken too much, please don't mind.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-9 11:15:01
| Show all posts
select t1.t1_date as thdDate, count(t1.t1_telephone) as t1phone, count(t2.t2_telephone) as t2phone
from t1, t2
where t1.t1_date = t2.t2_date
group by t1.t1_date;
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