Home Backend Development PHP Tutorial 像这种表,应该如何统计比较有效率

像这种表,应该如何统计比较有效率

Jun 13, 2016 am 10:09 AM
distinct from select table

像这种表,应该怎么统计比较有效率?
表里的内容如下:

id bid
1 138
2 150
3 139
4 139
5 139
6 138
7 138
8 150


我只要统计bid字段里的值,不要重复的

应该怎么统计比较有效率?

统计结果如下:
138
150
139

------解决方案--------------------
group by bid;
------解决方案--------------------
select distinct bid from table_name;
------解决方案--------------------
select distinct bid from table_name;
------解决方案--------------------
SELECT DISTINCT bid FROM t;

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Asynchronous processing method of Select Channels Go concurrent programming using golang Asynchronous processing method of Select Channels Go concurrent programming using golang Sep 28, 2023 pm 05:27 PM

Asynchronous processing method of SelectChannelsGo concurrent programming using golang Introduction: Concurrent programming is an important area in modern software development, which can effectively improve the performance and responsiveness of applications. In the Go language, concurrent programming can be implemented simply and efficiently using Channels and Select statements. This article will introduce how to use golang for asynchronous processing methods of SelectChannelsGo concurrent programming, and provide specific

How to hide the select element in jquery How to hide the select element in jquery Aug 15, 2023 pm 01:56 PM

How to hide the select element in jquery: 1. hide() method, introduce the jQuery library into the HTML page, you can use different selectors to hide the select element, the ID selector replaces the selectId with the ID of the select element you actually use; 2. css() method, use the ID selector to select the select element that needs to be hidden, use the css() method to set the display attribute to none, and replace selectId with the ID of the select element.

Using the distinct keyword in parsing SQL Using the distinct keyword in parsing SQL Feb 18, 2024 pm 09:21 PM

Detailed explanation of distinct usage in SQL In SQL databases, we often encounter situations where we need to remove duplicate data. At this time, we can use the distinct keyword, which can help us remove duplicate data and make the query results clearer and more accurate. The basic usage of distinct is very simple, just use the distinct keyword in the select statement. For example, the following is a normal select statement: SELECTcolumn_name

How to use mysql's DISTINCT How to use mysql's DISTINCT Jun 03, 2023 pm 05:56 PM

The DISTINCT keyword of mysql has many unexpected uses. 1. It can be used when counting non-duplicate records, such as SELECTCOUNT(DISTINCTid) FROMtablename; it is to count how many records with different IDs in the talbebname table. 2. When you need to return records For specific values ​​of different ids, you can use, for example, SELECTDISTINCTidFROMtablename; to return the specific values ​​of different ids in the talbebname table. 3. The above situation 2 will be ambiguous when you need to return results of more than 2 columns in the mysql table, such as SELECTDISTINCTid, type

How to use distinct and group by in MySQL How to use distinct and group by in MySQL May 26, 2023 am 10:34 AM

Let’s talk about the general conclusion first: when the semantics are the same and there is an index: both groupby and distinct can use the index, and the efficiency is the same. In the case of the same semantics and no index: distinct is more efficient than groupby. The reason is that both distinct and groupby will perform grouping operations, but groupby may perform sorting and trigger filesort, resulting in inefficient SQL execution. Based on this conclusion, you may ask: Why are groupby and distinct efficient when they have the same semantics and indexes? Under what circumstances does groupby perform sorting operations? Find answers to these two questions. Next, let’s take a look at dist

How to implement change event binding of select elements in jQuery How to implement change event binding of select elements in jQuery Feb 23, 2024 pm 01:12 PM

jQuery is a popular JavaScript library that can be used to simplify DOM manipulation, event handling, animation effects, etc. In web development, we often encounter situations where we need to change event binding on select elements. This article will introduce how to use jQuery to bind select element change events, and provide specific code examples. First, we need to create a dropdown menu with options using labels:

What is the usage of distinct in oracle? What is the usage of distinct in oracle? Jul 11, 2023 am 09:35 AM

Oracle's distinct usage can filter duplicate rows in the result set to ensure that the value of the specified column or columns returned in the "SELECT" clause is unique. The syntax is "SELECT DISTINCT column 1, column 2, column 3... from table name". "distinct" will sort the returned result set and can be used in conjunction with "order by" to improve efficiency.

What is the reason why Linux uses select? What is the reason why Linux uses select? May 19, 2023 pm 03:07 PM

Because select allows developers to wait for multiple file buffers at the same time, it can reduce IO waiting time and improve the IO efficiency of the process. The select() function is an IO multiplexing function that allows the program to monitor multiple file descriptors and wait for one or more of the monitored file descriptors to become "ready"; the so-called "ready" state is Refers to: the file descriptor is no longer blocked and can be used for certain types of IO operations, including readable, writable, and exceptions. select is a computer function located in the header file #include. This function is used to monitor file descriptor changes—reading, writing, or exceptions. 1. Introduction to the select function. The select function is an IO multiplexing function.

See all articles