How do I write an SQL query statement to get the result on the right from the source data on the lef

Updated on technology 2024-02-11
13 answers
  1. Anonymous users2024-02-06

    For example, the name of your table is a

    select a.Name, aGrades as Language, BGrades as Mathematics.

    from (

    select name, grade from a where subject=language) ainner join

    select name, grade from a where subject=mathematics) b on aName=b.Name.

  2. Anonymous users2024-02-05

    declare @sql nvarchar(max)set @sql=''--Initialize variable@sqlselect @sql=@sql+','+Subject from tablename group by Subject--Variable multi-value assignment.

    set @sql=stuff(@sql,1,1,''-- remove the first one','

    set @sql='select * from tablename pivot (max(fraction) for subject in ('+@sql+'))a'

    exec(@sql)

  3. Anonymous users2024-02-04

    declare @testtable table(name nvarchar(10),cause nvarchar(10),score int

    insert @testtable (name, cause, score)

    select n'a', n'Language', 1union select n'a', n'Mathematics', 2union select n'B', n'Language', 3union select n'B', n'Mathematics', 4union select n'C', n'Language', 5union select n'C', n'Mathematics', 6select * from @testtableorder by score

    select name, language, mathematics.

    fromselect name, cause, score from @testtable

    ppivot

    sum(score)

    for cause in

    Chinese, Mathematics).

    as pvt

    order by pvt.Language

  4. Anonymous users2024-02-03

    The data in the left table is obviously redundant, and SQL statements can be used to query the left table to write to the right table, but it can only be achieved by program looping.

    From the perspective of the database, the design of the left Min search side table obviously has the hidden problem of asking potatoes, and the structure of the right side table is reasonable.

  5. Anonymous users2024-02-02

    I'm afraid that the one on the right corresponds to the information in the database one by one.

    You can write select * from the table name and save it to an object, and use the object's properties to call the information to be displayed.

    If it is not a one-to-one correspondence and not all of them are displayed, the required entries can be selected, as follows:

    Select Meeting Date, Meeting Subject, Total Tasks, Meeting Minutes Master Record ID, Task Status, Incomplete, Completed on Time, In Progress from table name.

    If you can help the landlord, I hope to adopt it Thank you.

  6. Anonymous users2024-02-01

    --Somewhat similar to oracle row transliteration.

    select t.Date of the meeting, tConference Theme, tTotal number of tasks, tMeeting minutes master record id, decode(t..)Task status,'Not finished',t.Status Quantity) is incomplete.

    decode(t.Task status,'Completed on schedule',t.Status Quantity) Completed on schedule, decode(t.Task status,'Ongoing',t.Number of states) in progress.

    from t

    group by t.Date of the meeting, tConference Theme, tTotal number of tasks, tMeeting Minutes Master Record ID

  7. Anonymous users2024-01-31

    --**Enlarge, your policewoman is quite 6.

  8. Anonymous users2024-01-30

    --Is it just a line by line?

    select ,sum( new score from table name a, table name b where >= group by.)

  9. Anonymous users2024-01-29

    1. We first create a web page, use EF to import an entity model in the database, and then create a button, click the button and use EF to perform an insert operation in the database.

    2. Next, we open the database, then select the tool in the database toolbar, and then select the profile tool.

    3. After logging in, you will find that all the statements involved in the database are displayed here.

    4. Then we click the "Add" button in our project, and then check what operations he has done in our profile listener, the login user we use is sa, through which we can see the execution time of the statement.

    5. Executed SQL program.

    6. EF automatically performs the insertion operation, and these encapsulations are in the corresponding DLL file of the Entity Framework.

  10. Anonymous users2024-01-28

    1. First of all, we open the SQL Server Management Studio software.

    2. Then click the "+" sign in front of "Database" in the figure, Database.

    3. Then use the same method to click on the database marked by the red box in the figure, which is the database added by the user.

    4. Then click "Table" in the red box to replace it.

    6. Then click the database you added again, select it, and click New Query.

    7. Then a new page will appear on the right side of the software.

    8. Enter the SQL statement that conforms to the SQL syntax in the new page, and click "Query" marked in the figure to execute the SQL statement.

    9. Then the execution result will appear.

  11. Anonymous users2024-01-27

    With SQL statements, extracting results from the database is a query, and use select statements. The select statement belongs to the Data Query Language (DQL). The most basic ones are:

    select [Column 1, Column 2......]from [table name] where [condition].

  12. Anonymous users2024-01-26

    Does dt mean the same day?

    select , count(1)from table a

    left join table b on

    convert(varchar(10), 112)=convert(varchar(10), 112)

    and =and <

    where is not null

    group by ,order by

    Tens of billions?

  13. Anonymous users2024-01-25

    This can be achieved with group by+case.

    select Grade + Type Vehicle Grade Type, COUNT (license plate) Number of vehicles, SUM (number of seats) Number of seats, SUM(case when Zone Type in ('within the prefecture','Intercounty','Intermunicipal'then 1 else 0 end) the number of vehicles in the province, sum(case when area type in ('within the prefecture','Intercounty','Intermunicipal') then number of seats else 0 end) number of seats in the province, sum(case when area type in ('Interprovincial','International'then 1 else 0 end) number of vehicles in the province, sum(case when area type in ('within the prefecture','Intercounty','Intermunicipal') then number of seats else 0 end) number of seats in other provinces.

    from the table name.

    group by level+type.

Related questions
5 answers2024-02-11

F get domain contrast is a formatting function (should be written by yourself), the first parameter (arg prod spec id) according to the second parameter (120) formatting and return the result to the v bill code, according to the function naming method, the above ** should be the standard format for getting the date.

5 answers2024-02-11

With a view or an index.

create index >>>More

4 answers2024-02-11

sele date,a.win, b, lose from table, (sele date count(result) as win from table where rsult='Win'group by date )a,,(sele date count(result) as pay from table where rsult='Pay'group by date )b where table. date=table. >>>More

8 answers2024-02-11

sql2008 statement:

select name = case when num = 1 then a else''end, grades, subjects. >>>More

15 answers2024-02-11

1.It's interesting to understand, but the reality should be: if there are more than two fields after order by, then all the records in the result set are sorted by the previous field, and the same part of the previous field is sorted by the next field. For example: >>>More