The table has three columns: stunamem and subject score.Table data includes:Zhang San Language 0Li Si Language 4Wang 'er English 90Zhang San, mathematics 333The query results are as follows:Chinese and English mathematics for studentsZhang San 0 0 33
Normal row-column conversion (version 1.0) only provides static and dynamic writing for SQL Server 2000, and Version 2.0 adds SQL Server 2005 writing.
Question: Suppose there is a student orders table (TB) as follows:
Name course score
Zhang
Normal row-column conversion (version 1.0) only provides static and dynamic writing for SQL Server 2000, and Version 2.0 adds SQL Server 2005 writing.
Question: Suppose there is a student orders table (TB) as follows:
Name course score
Zhang
In the following table, take the row with the largest field.Field a field cSP000016964 5 20SP000016964 7 30SP000016964 1 15SP000017755 4 16SP000017755 8 12The following result is obtained.SP000016964 7 30SP000017755 8 12 The code is as follows:Copy
Mysql> Select COUNT (*) as Count , name,sum (age) as the age of T1 group by name order by Count desc;+-------+--------+- -----+| Count | Name | Age |+-------+--------+------+| 3 | Atest | | | 2 | Btest | Panax Notoginseng | | 2
Reading directory
I. Preface
Ii. First Thought
Iii. Second Thought
4. The third thought
I. Preface
In some of our projects, we often encounter the problem of converting rows into columns. Now let's discuss how we can convert Table 1 to
Question: Suppose there is a student score table (TB) as follows:
Name Course Score
John Language 74
John Math 83
John Physics 93
Dick Language 74
Dick Math 84
Dick Physics 94
Want to become (get the following results):
Name Chinese mathematics
One or more rows into a column (and separated by ",")Table Name: ATable data:Desired Query Results:Query statement:Select Name, value = (STUFF (select ', ' + value from A WHERE name = Test.name
Demo and introduction of common operation methods under MySQL database commands ~, Mysql database
Mysql database
To install mysql, go to the Baidu tutorial.
Start DatabaseThe password set by mysql-u root-p under cmdCommandShow databases; view the
1. Query duplicate records based on a single field (name) in the tableSELECT * FROM user WHERE name IN (SELECT name FROM user group by name having count (name)> 1 );2. Delete duplicate records based on a single field (name) in the table. Only
1. During the interview, I encountered a problem. I wrote a table with two fields, ID and name, to query all the data with duplicate names. The column is:
Select * from Xi A where (A. username) in (select username from Xi Group by username having
The SQL statement I used:
Delete from fp_sgfpxxWhere fphm in (select fphm from fp_sgfpxx group by fphm having count (fphm)> 1)And rowid not in (select min (rowid) from fp_sgfpxx group by fphm having count (fphm)> 1)
Delete duplicate invoice
Normal row-column conversion (version 1.0) only provides static and dynamic writing for SQL server 2000, and version 2.0 adds SQL server 2005 writing.
Question: Suppose there is a student orders table (tb) as follows:
Name course score
Zhang San
Question: Suppose there is a student orders table (TB) as follows:
Name course score
Zhang San Language 74
James math 83
Zhang San physical 93
Li Si language 74
Li Si mathematics 84
Li Si physical 94
(The following result is displayed ):
Name,
Mysql searches for the list of duplicate names with the largest age
mysql> select count(*) as count ,name,sum(age) as age from t1 group by name order by count desc;+-------+--------+------+| count | name | age |+-------+--------+------+| 3 |
A, SQL and sequelize in the group query
grouping queries in 1.1 sql
In SQL query, the wildcard GROUP BY name implements a grouped query. GROUP BYclauses are used in conjunction with aggregate functions to complete a grouped query, and in a SELECT
Source of the article: Understanding Group BY and aggregate functions
Let's take a look at table 1, the table named test:
Table 1
Execute the following SQL statement:
1 2
SELECT name from test GROUP by name
You should
In the process of preparing a database interview, first on the Internet a sea search, to find the history of interview questions, and then a bone a bone after the gnawing, now basically these problems (or called practice) are no problem. The
Reprint Http://hi.baidu.com/my_favourate/item/3716b0cbe125f312505058ebSQL query multiple non-repeating record values brief analysis 2008-02-28 11:36 below test under Oracle 10gBecause of the design needs, need to query the record value of the same
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.