Maximum of Column per Group in MySQL

AmitDiwan
Updated on 09-Mar-2021 13:11:12

159 Views

Let us understand how to find the maximum of a column per group in MySQL −SELECT colName1, MAX(colName2) FROM tableName GROUP BY colName1 ORDER BY colName1;We will now see a live example. Let’s say we have a table PRODUCT −+---------+--------+ | Article | Price  | +---------+--------+ | 1       | 255.50 | | 1       | 256.05 | | 2       | 90.50  | | 3       | 120.50 | | 3       | 123.10 | | 3       | 122.10 | +---------+--------+Following is the query to get the maximum of column per group −QuerySELECT Article, MAX(Price) AS MaxPrice FROM Product GROUP BY Article ORDER BY Article;Output+--------------+--------------+ | Article      | MaxPrice | +--------------+--------------+ | 0001         | 256.05 | | 0002         | 90.50 | | 0003 | 123.10 | +--------------+--------------+

Why files are needed in C programming language?

Bhanu Priya
Updated on 09-Mar-2021 10:04:35

4K+ Views

Files is collection of records (or) it is a place on hard disk, where data is stored permanently. By using C commands, we access the files in different ways.Need of files in C languageEntire data is lost when the program terminates and storing in a file will preserve your data even if the program terminates.If you want to enter a large amount of data, normally, it takes a lot of time to enter them all.If you have a file containing all the data, you can easily access the contents of the file by using few commands in C.You can easily ... Read More

Write a structure in local scope program using C language

Bhanu Priya
Updated on 09-Mar-2021 09:53:13

486 Views

Structure is a collection of different datatype variables, grouped together under a single name.Features of structureThe features of structure are explained below −It is possible to copy the contents of all structure elements of different datatypes to another structure variable of its type by using an assignment operator.For handling complex datatypes, it is better to create a structure within an another structure, which is called as the nested structures.It is possible to pass an entire structure, individual elements of a structure and an address of structure to a function.It is also possible to create the structure pointers.Declaration of structuresThe general ... Read More

Explain the concept of Uninitialized array accessing in C language

Bhanu Priya
Updated on 09-Mar-2021 09:48:46

1K+ Views

ProblemIn C language, is the program executed, if we use an uninitialized array?SolutionIf we use any uninitialized array, compiler will not generate any compilation and an execution error.If an array is uninitialized, you may get unpredictable result.So, it’s better we should always initialize the array elements with default values.Example ProgramFollowing is the C program of accessing an uninitialized array − Live Demo#include int main(void){    int a[4];    int b[4] = {1};    int c[4] = {1,2,3,4};    int i; //for loop counter    //printing all alements of all arrays    printf("Array a:");    for( i=0; i

What is out of bounds index in an array - C language?

Bhanu Priya
Updated on 09-Mar-2021 09:46:45

3K+ Views

Suppose you have an array with four elements. Then, an array indexing will be from 0 to 3, i.e., we can access elements from index 0 to 3.But, if we use index which is greater than 3, it will be called as an index out of bounds.If, we use an array index which is out of bounds, then the compiler will compile and even run. But, there is no guarantee for the correct result.Result can be not sure and it will start causing many problems. Hence, it is advised to be careful while using an array indexing.Example ProgramFollowing is the ... Read More

Give the clarity on Pointer structures with suitable example in C language

Bhanu Priya
Updated on 09-Mar-2021 09:45:25

209 Views

Pointer to structure holds the address of an entire structure.Mainly, these are used to create the complex data structures such as linked lists, trees, graphs and so on.The members of the structure can be accessed by using a special operator called arrow operator ( -> ).DeclarationFollowing is the declaration for pointer to structure −struct tagname *ptr;For example, struct student *s;AccessingYou can access pointer to structure by using the following −Ptr-> membername;For example, s->sno, s->sname, s->marks;ExampleFollowing is the C program of the pointer structures −#include struct student{    int sno;    char sname[30];    float marks; }; main ( ){   ... Read More

How to pass the address of structure as an argument to function in C language?

Bhanu Priya
Updated on 09-Mar-2021 09:39:31

623 Views

Passing the address of structure as an argument to function −The Address of the structure is passed as an argument to the function.It is collected in a pointer to structure in function header.AdvantagesNo wastage of memory as there is no need of creating a copy againNo need of returning the values back as the function can access indirectly the entire structure and work on it.Example#include struct date{    int day;    int mon;    int yr; }; main (){    struct date d= {02, 01, 2010};    display (&d);    getch (); } display (struct date *dt){    printf("day = ... Read More

How to pass individual members of structure as arguments to function in C language?

Bhanu Priya
Updated on 09-Mar-2021 09:38:44

1K+ Views

Passing individual members as arguments to function −Each member is passed as an argument in the function call.They are collected independently in ordinary variables in function header.Example#include //Declaring structure// struct student{    int s1,s2,s3; }s[5]; //Declaring and returning Function// void addition(int a,int b,int c){    //Declaring sum variable and For loop variable//    int i,sum;    //Arithmetic Operation//    for(i=1;i

Declaring a structure with no members in C language

Bhanu Priya
Updated on 09-Mar-2021 09:35:11

1K+ Views

ProblemCan we declare a structure with no members in C, if yes what will be the size of that structure?SolutionYes, it is allowed in C programming language that we can declare a structure without any member and in that case the size of the structure with no members will be 0 (Zero). It will be a Zero size structure.Example Live Demo#include //structure with no members struct temp{ }; int main(){    //declaring structure variable    struct temp T;    printf("Size of T: %d", sizeof(T));    return 0; }OutputIn this C program, we are declaring a structure named "temp" without declare ... Read More

Finding number of alphabets, digits and special characters in strings using C language

Bhanu Priya
Updated on 09-Mar-2021 09:20:25

854 Views

Following is the logic we implement to find alphabets, digits and special characters −for(number=0;string[number]!='\0';number++) {// for loop until endof string    if(string[number]>='a'&&string[number]='A'&&string[number]='0'&&string[number]='a'&&string[number]='A'&&string[number]='0'&&string[number]

Advertisements