How to import tier pricing-advanced price using csv in Magento 2?

In Magento 2 Import tier pricing is such a simple way.
You need to Create CSV file for import advanced pricing in Magento 2 sometimes Tier price is called as Advanced Pricing.

Tier price is used when you want to give discount on bulk purchase of product whether based on customer group, based on Quantity you purchase.

Go To Admin panel in Magento 2,
Click On System from Left Menu,
System -> Import -> Import Settings -> Advanced Pricing
Select Import Behaviour as Add/Update for first time pricing import for a product,

Below is column name for tier price import CSV
sku Product SKU
tier_price_website Website Code (Default ALL Website)
tier_price_customer_group Customer Group
tier_price_qty No. of Quantity to purchase for getting discount on a price
tier_price_value_type tier price value fixed/discount of the actual price

Download  Tier price CSV for demo, Tier Price CSV

If you want to replace old value of tier price with New You have to select Replace field from Import behavior in Import Tier price section from Admin panel otherwise price value will be added again for product.

Check Default Behaviour of Product import for Add, Replace and Delete function for Product import behavior.

If you don’t know about Import simple product refer link,Import Simple Product Using CSV Magento 2

Direct SQL Queries in Magento 2?

There are some situations where executing direct SQL queries would be simple and much quicker leading to a more optimized Magento getCollection query.

On a large data set of entity, Saving each individual entity can take a long time with resource hungry and therefore make the system unusable. Overcome this issue it is possible to issue a direct SQL query which could update large set of data of an entity in a fewer seconds.

By default, Magento will automatically connect to it’s database using class Magento\Framework\App\ResourceConnection with getConnection() function.

Using below code snippet you can get a resourceConnection for run row sql query. Create Block file,

calling from template file,

Reading From The Database All the records, 

fetchAll() => This method Fetches all SQL result rows as a sequential array.
This method takes a query as it’s the first parameter, executes it and then returns all of the results as an array. Using this we can get all records of database table.

Result will be all the records of customer entity as array.
fetchCol() => This method Fetches the first column of all SQL result rows as an array.

The result looks like,

 

fetchOne() => This method Fetches the first column of the first row of the SQL result.

Using fetchOne you can get only single result value. In the above query, you can get email id as result.

Update Query: Update Records in Database table which already exist.

Delete Query: Delete specific row from database table.

Insert Query: Insert single record in database table using row query. The first Parameter is table name
In below example, We will add record into review table.

New Record will be inserted in review table.

insertArray Query: Insert array into a table based on columns definition.
Pass only those columns which value you want to insert in second parameter column and the third parameter is data of the specific column.
In below example, We will add the record into review table.

Above query insert the new record in table by column-wise.

There are many other row query function related to database. You can get all the sql function from file Magento/framework/DB/Adapter/AdapterInterface.php