当前位置:网站首页>Bi-sql Union

Bi-sql Union

2022-06-25 01:12:00 Powerbi white tea

UNION sentence

UNION Statement similar to PowerQuery Append query in , You can merge two tables or two datasets up and down .DAX There's also... In the function UNION, And the usage is very similar .

UNION Use requires the same number of columns in both datasets , The data types of the two dataset columns are exactly the same , And the order of columns should be consistent .

except UNION outside , also UNION ALL sentence . The difference between the two is that the data set returned by the former has no duplicates , The data set returned by the latter contains duplicates .

Basic grammar

UNION grammar :

SELECT  Column name (s) FROM  surface 1
UNION
SELECT  Column name (s) FROM  surface 2

UNION ALL grammar :

SELECT  Column name (s) FROM  surface 1
UNION ALL
SELECT  Column name (s) FROM  surface 2

Using examples

Case data :

In the database of white tea machine , There is a name “TEST” The database of , There is a name “ Babies ” and “ Mixed class ” Case data for .

Example 1:

stay PowerBI Use in UNION Statement to merge two tables .

SELECT * FROM  Babies 
UNION
SELECT * FROM  Mixed class 

give the result as follows :

Example 2:

stay PowerBI Use in UNION ALL Statement to merge two tables .

SELECT * FROM  Babies 
UNION ALL
SELECT * FROM  Mixed class 

give the result as follows :

Contrast examples 1 We can easily find the result of , Duplicate items of mixed classes are preserved .

Example 3:

stay PowerBI Use in UNION Statement to convert... In two tables [ Classification of goods ] Column to merge .

SELECT  Classification of goods  FROM  Babies 
UNION
SELECT  Classification of goods  FROM  Mixed class 

give the result as follows :

Example 4:

stay PowerBI Use in UNION Statement to the infant class [ Classification of goods ] Columns and mixed classes [ The sale price ] Column to merge .

SELECT  Classification of goods  FROM  Babies 
UNION
SELECT  The sale price  FROM  Mixed class 

give the result as follows :

Because the column data types in the two datasets are different , So the result is an error .

Have a chat :

about PowerBI The cognitive , White tea prefers to be called a container 、 platform .

Compare with others BI For class software , Microsoft PowerBI More compatible , Compatible with many other languages .

for instance :Python、R Language 、SQL Language 、Mysql Language, etc. .

So the partners used other languages in the development process , Be sure to pay attention to some development specifications and detailed requirements of the language .

because PowerBI As a platform, it can be compatible with these languages , It is also required to follow the original requirements of these languages .

for instance :Mysql To distinguish between keywords and ordinary characters , Backquotes introduced . And in the SQL Server There is no concept of backquotes in , Only single quotation marks . So we have PowerBI Use in SQL When querying , These details also need to be observed .

This is white tea , One PowerBI Beginners .

原网站

版权声明
本文为[Powerbi white tea]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210542593964.html