| |

VerySource

 Forgot password?
 Register
Search
View: 821|Reply: 5

Query multiple issues merged into one record at a time

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-4 10:00:01
| Show all posts |Read mode
I have two tables with the following structure:

Form A

Field Type Meaning
DataValue float
DataKind int data type range 0-7 8 data indicators respectively representing a group of data
DataTime datetime


As shown above, each set of data should contain 8 data indicators, but there are 8 records in the database. Can the contents in table A be combined into one record through SQL and given different field names respectively.
Reply

Use magic Report

0

Threads

12

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-5-17 06:45:01
| Show all posts
Use crosstab query.
Reply

Use magic Report

0

Threads

35

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-5-17 16:15:01
| Show all posts
Search "row transfer"
Reply

Use magic Report

0

Threads

40

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-18 10:30:01
| Show all posts
case .... when ..... then ...
Reply

Use magic Report

0

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-18 21:15:02
| Show all posts
reference
declare @sql varchar (4000)
set @sql = 'select Name'
select @sql = @sql + ', sum (case Subject when' '' + Subject + '' 'then Result end) [' + Subject + ']'
from (select distinct Subject from CJ) as a
select @sql = @ sql + 'from test group by name'
exec (@sql)
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-5-19 12:45:01
| Show all posts
--such?
create table T (id int, type int)
insert T select 1, 1
union all select 1, 2
union all select 1, 3
union all select 2, 3

select id,
'A' = max (case type when 1 then 1 end),
'B' = max (case type when 2 then 2 end),
'C' = max (case type when 3 then 3 end)
from T
group by id

--result
id A B C
----------- ----------- ----------- -----------
1 1 2 3
2 NULL NULL 3

(2 row (s) affected)
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