Oracle 查询不重复多列SQL写法
Oracle中要求查询表customer 中 t.address , t.customer_name不重复的列:
Oracle中要求查询表customer 中 t.address , t.customer_name不重复的列:
通常想法是:
select distinct t.address , t.customer_name from customer t
然而这种写法在oracle是错误的。
因此有第二种想法:
select count(*) from ( select distinct t.address , t.customer_name from customer t)
这种写法是正确的,然而有没有更好的写法呢
突发奇想的第三种,充分利用了||的连接功能:
select count(distinct t.address ||t.customer_name) from customer t
这样不就ok了吧,其实不是的,看看下面这种情况就知道了
若第一条记录为:
address= testAddT ,customer_name=omcat
第二条记录
address= testAdd ,customer_name=Tomcat
这种情况t.address ||t.customer_name得出的值都是一样的,然而显然这两条记录是不同的,如何解决这种问题呢,,就是加入特殊字符来解决,比如我们确定这两列字段中不会出现#这样的字符内容,好办,此时就可以写出如下完美的sql语句了
select count(distinct t.address ||'#'||t.customer_name) from customer t
最后说明:不同的数据库中的sql查询语法都可能都会有差别的所以要针对特定数据库而言,不过思想是可以借鉴的,因此重要的是理解灵活的解决问题思想。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.
