Posts

Showing posts from December, 2018

SQL Syntaxes

Select data from a table To select all(*) the data from a table  SELECT * FROM TABLE_NAME; To select specific columns of a table SELECT COLUMN_1, COLUMN_2,..., COLUMN_n FROM TABLE_NAME; ; DISTINCT - To select distinct(different) values SELECT DISTINCT COLUMN_1, COLUMN_2,..., COLUMN_n FROM TABLE_NAME; To list the number of distinct rows SELECT COUNT(DISTINCT COLUMN_NAME) FROM TABLE_NAME; or SELECT COUNT(*) AS COLUMN_NAME_IDENTIFIER FROM (SELECT DISTINCT COLUMN_NAME FROM TABLE_NAME); To give a condition to the select statement SELECT COLUMN_1, COLUMN_2,...,COLUMN_n FROM TABLE_NAME  WHERE condition When using the WHERE condition, 1. if it's an integer COLUMN_NAME = INT_VALUE 2. if it's a string (single quotation is required) COLUMN_NAME = 'STRING_VALUE' 3. if it's a date (single quotation is required and the format must be YYYY-MM-DD) COLUMN_NAME = 'YEAR-MONTH-DATE' Using AND syntax with WHERE con

Supporting code snippets for OOP take home assignment

Open a file and read data line by line. You're given a text(.txt) file as the input and not allowed to do manual user inputs. So you have to read the text file using your program. It can be done in the following way. Here the line is taken into a String called 'line'. To read lines you have to use the library 'fstream' #include <fstream> string line; ifstream myfile ("yourfilename.txt"); if (myfile.is_open()){ while(getline(myfile,line)){ // Enter your code here } myfile.close(); } src :  http://www.cplusplus.com/doc/tutorial/files/ Spliting string into two with blank space Method 1 Here 'line' is the String which we read from the file. To store the two sub strings we use a vector called tokens of type String. If you use this method after splitting the string into two parts you have to cast it into int. #include <vector> #include <string> #include <sstream> #include <it