Skip to main content

Posts

Showing posts with the label sql

SORT BASE ON COUNT

Query to select feilds group by column and order by number of counts of feilds. || SELECT type , count (*) FROM vehicles group by type order by count (*) desc   || SELECT `userid`, count( *) FROM `library` group by `userid` order by count( *) desc   || SELECT `userid`, count( favourite) FROM `library` group by `userid` order by count( favourite) desc   ERROR : SELECT list is not in GROUP BY clause and contains nonaggregated column … incompatible with sql_mode=only_full_group_by SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

User database table

-- phpMyAdmin SQL Dump -- version 4.6.5.2 -- https://www.phpmyadmin.net/ -- -- Host: localhost -- Generation Time: Mar 09, 2019 at 09:17 AM -- Server version: 10.1.21-MariaDB -- PHP Version: 7.1.1 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `sample_db` -- -- -------------------------------------------------------- -- -- Table structure for table `user` -- CREATE TABLE `user` ( `id` int(11) NOT NULL, `username` varchar(255) NOT NULL, `mobile` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `role` varchar(150) NOT NULL, `date` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Indexes for dumped tables -- -- -- Indexes for t...

SQL

****** Count "yes" or "no" ************** SELECT COUNT(case when decision="yes" THEN decision end )as yes, COUNT(case when decision="no" THEN decision end )as no, COUNT(case when decision="unsure" THEN decision end ) as unsure,COUNT(decision) FROM `election` WHERE `dispute_id` = '2' _____________________________________________ SELECT MAX(`date`) FROM stylist_payment WHERE `stylitid` ='390' > SELECT MAX(`date`) FROM stylist_payment GROUP BY `stylitid` > SELECT `stylist_payment`.`stylitid`, `stylitamount`, `percentage`, `si_amount`, `stylist_payment`.`date` FROM `stylist_payment` LEFT JOIN `booking` ON `booking`.`stylitid` = `stylist_payment`.`stylitid`GROUP BY `stylitid` SELECT MAX(`stylist_payment`.`date`) FROM stylist_payment LEFT JOIN `user` ON `user`.`id` = `stylist_payment`.`stylitid` GROUP BY `stylitid` SELECT stylitid,total_amount,user.username,user.firstname,user.lastname,user.contact,user.ema...