Discover sql count distinct values, include the articles, news, trends, analysis and practical advice about sql count distinct values on alibabacloud.com
multiple products at the same time.Select T.product_group,count (t.user_id) from(Select O. user_id , Group_concat (Distinct o. product_id ORDER by O. product_id ASC SEPARATOR ') ' Product_group ' from Order_list oGROUP by O.user_id) TGROUP BY T.product_group*/Query A/b/c/d/ab/ac/ad/bc/bd/cd/abc .... How many people are there in a 4+6+4+1=15 combination?Select O. product_id ,
example uses Contain to find the customer who contains an order with OrderID 10248.2. contains multiple values:
string[] cities = new string[] { "Seattle", "London", "Vancouver", "Paris" };var q = db.Customers.Where(p=>cities.Contains(p.City)).ToList();
Statement Description: This example uses Contains to find customers in the cities of Seattle, London, Paris, or Vancouver.
To sum up, we illustrate the following statements:
Group By/Havi
Tags: SQL countSQL count () functionfunction returns the number of rows matching the specified criteria
sqlcount (column_name) Syntax
returns the number of values for the specified column (NULL does not count in )SELECT COUNT (column_name) fromtable_name
The following statement is used to count the number of people with the same name and surname. Very good. For more information, see.
The following statement is used to count the number of people with the same name and surname. Very good. For more information, see.
SQL statement Query
The table structure is as follows:
ID name gender
1 Michael
2. Wang Si male
SQL statement of one of the IT Ninja Turtles-connecting all values of the same field, Ninja Turtles SQL
Oracle can use SYS_CONNECT_BY_PATH string to aggregate functions: select ltrim (MAX (SYS_CONNECT_BY_PATH (productname, ','), ',') AS productnameFROM (SELECT '1' as id, productname, ROW_NUMBER () OVER (partition by '1' order by productname) AS curr, ROW_NUMBER
n = new value ... WHERE (filter condition);For example: UPDATE Student SET id = 2,age =20 WHERE name = ' John '
Update to delete data: Update Student age= nullwhere name = ' John '
4: Delete data: Delete from table name WHERE (filter bar
For example: DELETE fromstudent WHERE name = ' John
Note: Delete all table data to remove filter conditions, or use TRUNCATE table name
Simple data query1: Query: SELECT column name from table name;For example: SELECT ID from Student;
Query full table dat
SQL statement Query
The table structure is like this:
ID name Sex
1 Three men
2 Wang Shinan
3 Lili Girl
4 Three Men
5 Chao Liuan
6 Noble Male
7 Wang Shiju
8 Noble Women
9 Three Girls
How can I query the following results with an SQL statement
Names, number of men, numbers of women, including IDs.
Zhang 33 2 1 1,4,9
Wang 42 1 1 2,7
Lili 1 0 1 3
Noble 2 1 1 6,8
Zhao Liu 1 1 0 5
Copy Code code as follow
Reference Problem description:
There are three tables:
Student Information table S (sno, sname)
Course information table C (cno, cname, cteacher)
Student-course relationship table SC (sno, cno, scroce)
Question 1: find out the names of all students who have not taken the course taught by Mr. Li Ming.
Question 2: The name of two or more failed students is displayed.
Question 3: find out the names of students who have selected both course "1" and course "2 ".
Main test: group by, inner join, havi
Database environment: SQL SERVER 2005
An existing product sales Real-time table, table data as follows:
The field name is the product name, the field type is the sales type, 1 is sold, 2 is the return, the field num is the quantity, and the field CTime is the operating time.
Requirements:
Count the sales (sale, return) of all goods within 24 hours on one line, taking into account the date.
Analysis:
SQL statement Query
The table structure is like this:
ID name Sex
1 Three men
2 Wang Shinan
3 Lili Girl
4 Three Men
5 Chao Liuan
6 Noble Male
7 Wang Shiju
8 Noble Women
9 Three Girls
How can I query the following results with an SQL statement
Names, number of men, numbers of women, including IDs.
Zhang 33 2 1 1,4,9
Wang 42 1 1 2,7
Lili 1 0 1 3
Noble 2 1 1 6,8
Zhao Liu 1 1 0 5
Copy Code code as follows:
Execute the following SQL
Declare
@ T
Int
Exec
(
'Set
@ T = 1
'
)
Print
(
@ T
)
The following error is reported!Server: Message 137, Level 15, status 2, Row 1Variables must be declared'@ T'.
Actually, variables and dynamic statements cannot be shared,
In this case,Declare@ TIntSet@ T=1Print(@ T)
Or
Exec
(
'
Declare @ t int;Set @ T = 1;Print (@ T)
'
)
But sometimes you must combine va
Tags: using OS io data ar new SQL RGBThe function is to calculate how many rows match a condition.1 does not represent the first field, but rather represents a fixed value, count (1) and COUNT (2) effect are the sameCount (*), the execution of the asterisk will be translated into the specific name of the field, the effect is the same, but more than a translation
Common functionsAVG (average) COUNT (count) MAX (maximum value) MIN (minimum value) SUM SumThe syntax for applying a function is:Select from "table name";For example, if we were to find the sum of the Sales fields from our demo table,SELECT SUM from Store_information;Results:27502750 represents the sum of all Sales fields: 1500 + 250 + 300 + 700.In addition to the use of functions,
indexed. Therefore, some qualified data may not be found during query. In count (expr), nvl (column name, 0) is used for processing and then query.G. The sorting time is larger than other data (the index is sorted in descending order by default, small → large), so the NULL value is always at the end.Is null and is not null are an integral whole. Changing to IS or is not is incorrect. We can see the difference between NULL and NULL strings from the ab
When the SQL statement deletes duplicate records and there is no size relationship between them, it processes repeated values.
When the SQL statement deletes duplicate records and there is no size relationship between them, it processes repeated values.
When the SQL state
Tags: src log val Student technology share aggregate function personal insert upper As we all know, aggregate functions are statistical, and the Count function is the number of rows, that is, the number of rows that satisfy a certain condition. Let's look at this subtle relationship between count and null. CREATE TABLE dbo. Student (Snoint NULL, Name nvarchar ( at) ) INSERT into dbo. Student (Sno,name)
) AS BEGIN DECLARE @tbname varchar () Declare Tbroy cursor FOR SELECT Name from sysobjects where xtype= ' u '--the first cursor iterates through all tables open Tbroy fetch next from Tbroy to @tbname while @ @fetch_s Tatus=0 BEGIN DECLARE @colname varchar (DECLARE) Colroy cursor for select name from syscolumns where id=object_ ID (@tbname) and Xtype in (the Select Xtype from systypes where name in (' varchar ', ' nvarchar ', ' char ', ' nchar ')--data A field of type character)--the second cu
considered a record. Such as:Select COUNT (Price code) from productFirst/last functionThe first function, the last function, returns the data in the specified field that meets the query criteria, and the last record.The syntax is first (expression) and last (expression). An equation can be a field name, an expression, or a function that can be an internal or consumer defined, but not a SQL function.Min/ma
you execute the following statement:1 Update Set = (Selectdistinctfrom the leftjoinon= id_a); 2 1241 (210001column(s)So how do you turn the above result into a column that contains only b_name?(2) distinct by a_id to remove repeated rows after the a_id columnThis is also solved, the handle query and then nested a bit can be:Select from (Selectdistinctfrom the leftjoinon= id_a) t;OK, try the UPDATE statement again 1 update a_user set a_name = (s
function.Create table tb (id int, value varchar (10 ))Insert into tb values (1, 'A ')Insert into tb values (1, 'bb ')Insert into tb values (2, 'aaa ')Insert into tb values (2, 'bbb ')Insert into tb values (2, 'ccc ')Go
-- Create a merged FunctionCreate function f_hb (@ id i
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.